Trigger opening user form

faisalosama

New Member
Joined
Feb 6, 2021
Messages
3
Office Version
  1. 365
Platform
  1. Windows
If i have two user forms usrform1 and usrform2 and in the usrform 1 there is cmb box with data validation list that have options such as cut, damage property...etc, So id i selected cut then pressed add button, I need new form to be opened automatically to add new data related to cut, how can is make that.
 

Excel Facts

What do {} around a formula in the formula bar mean?
{Formula} means the formula was entered using Ctrl+Shift+Enter signifying an old-style array formula.
Hi,

Use below code to open userform2 when Cut is selected in Userform1.
The combobox name in my userform1 is cboItems.

VBA Code:
Private Sub cboItems_Change()
If cboItems.Value = "Cut" Then
    Me.Hide
    UserForm2.Hide
    UserForm2.Show
End If
End Sub
 
Upvote 0
Hi,

Use below code to open userform2 when Cut is selected in Userform1.
The combobox name in my userform1 is cboItems.

VBA Code:
Private Sub cboItems_Change()
If cboItems.Value = "Cut" Then
    Me.Hide
    UserForm2.Hide
    UserForm2.Show
End If
End Sub
Hello;

I used it and it is worked then after I completed the userform2 i tried it again and it is not working now

Code:
Private Sub btnAdd_Click()
lastrow = WorksheetFunction.CountA(Sheets("Injuries").Range("A:A"))

Sheets("Injuries").Cells(lastrow + 1, 1).Value = lastrow
Sheets("Injuries").Cells(lastrow + 1, 2).Value = usrForm2.cmbInjuryStatues.Value
Sheets("Injuries").Cells(lastrow + 1, 3).Value = usrForm2.cmbInjuryPart.Value
Sheets("Injuries").Cells(lastrow + 1, 4).Value = usrForm2.cmbJnjurynatuer.Value
Sheets("Injuries").Cells(lastrow + 1, 5).Value = usrForm2.cmbInssurance.Value

End Sub


Private Sub cmbJnjurynatuer_Change()

End Sub

Private Sub CommandButton1_Click()
Dim staff_id As String
staff_id = Trim(txtStaffnumber.Text)
lastrow = Worksheets("sheet1").Cells(Rows.Count, 2).End(xlUp).Row
For i = 2 To lastrow
If Worksheets("sheet1").Cells(i, 2).Value = staff_id Then

TextBox2.Text = Worksheets("sheet1").Cells(i, 3).Value
TextBox3.Text = Worksheets("sheet1").Cells(i, 4).Value
TextBox4.Text = Worksheets("sheet1").Cells(i, 5).Value
TextBox5.Text = Worksheets("sheet1").Cells(i, 6).Value
End If
Next

End Sub
This is the code in userform2


and this is for first one

Code:
Private Sub btnClear_Click()
usrForm.txtDescription.Value = ""
usrForm.txtLocation.Value = ""
usrForm.cmbCategory.Value = ""
End Sub

Private Sub cmbCategory_Change()
If cmbCategory.Value = "vehicle" Then
    Me.Hide
    usrForm2.Hide
    usrForm2.Show
End If
End Sub

Private Sub btnAdd_Click()

lastrow = WorksheetFunction.CountA(Sheets("Report").Range("A:A"))

Sheets("Report").Cells(lastrow + 1, 1).Value = lastrow
Sheets("Report").Cells(lastrow + 1, 5).Value = usrForm.txtLocation.Value
Sheets("Report").Cells(lastrow + 1, 6).Value = usrForm.txtDescription.Value
Sheets("Report").Cells(lastrow + 1, 4).Value = usrForm.cmbCategory.Value
End Sub
 
Last edited by a moderator:
Upvote 0
What error are you getting ?

What is happening when you click on button?
 
Upvote 0
Welcome to the MrExcel Message Board!

Cross-posting (posting the same question in more than one forum) is not against our rules, but the method of doing so is covered by #13 of the Forum Rules.

Be sure to follow & read the link at the end of the rule too!

Cross posted at: Trigger opening user form
If you have posted the question at more places, please provide links to those as well.

If you do cross-post in the future and also provide links, then there shouldn’t be a problem.

Also, please use code tags when posting code.
 
Upvote 0
Please check spelling and case.

Vehicle or vehicle ?
 
Upvote 0

Forum statistics

Threads
1,214,832
Messages
6,121,849
Members
449,051
Latest member
excelquestion515

We've detected that you are using an adblocker.

We have a great community of people providing Excel help here, but the hosting costs are enormous. You can help keep this site running by allowing ads on MrExcel.com.
Allow Ads at MrExcel

Which adblocker are you using?

Disable AdBlock

Follow these easy steps to disable AdBlock

1)Click on the icon in the browser’s toolbar.
2)Click on the icon in the browser’s toolbar.
2)Click on the "Pause on this site" option.
Go back

Disable AdBlock Plus

Follow these easy steps to disable AdBlock Plus

1)Click on the icon in the browser’s toolbar.
2)Click on the toggle to disable it for "mrexcel.com".
Go back

Disable uBlock Origin

Follow these easy steps to disable uBlock Origin

1)Click on the icon in the browser’s toolbar.
2)Click on the "Power" button.
3)Click on the "Refresh" button.
Go back

Disable uBlock

Follow these easy steps to disable uBlock

1)Click on the icon in the browser’s toolbar.
2)Click on the "Power" button.
3)Click on the "Refresh" button.
Go back
Back
Top