VBA code error checking

Ozroly

New Member
Joined
Feb 8, 2017
Messages
2
I'm making a userform that has multiple text boxes, for Example Combobox1 = ReasonForRequestField and Combobox2 = Requestnotcreatedfield, if Combobox1 = Reason 1 or Reason 2 then the validation will require the user to select an outcome from Combobox2, but if Combobox1 = Reason 3 or 4 then Combobox2 is not required.

i have tried the validation below but it wont allow me submit with Reason 1 in Combobox1

If Me.ReasonForRequestField.Value = "Reason1" Then

MsgBox " Please select a reason from Drop Down below " , vbExclamation, " Request not created field "

Me.Requestnotcreatedfield.SetFocus

Exit Sub

End If

i found this example on here but couldnt figure out how to adapt the variables to my form

If combobox1.Text = "1 - 2 yr" And (CDbl(textbox2.Value) < 1 Or CDbl(textbox2.Value) > 2) Then MsgBox ("Enter correct value") ElseIf combobox1.Text = And Then... End If

i hope i explained what i'm after ok, Any help would be Greatly appreciated :)

Thanks.
 

Excel Facts

Select all contiguous cells
Pressing Ctrl+* (asterisk) will select the "current region" - all contiguous cells in all directions.
You could model it along these lines.

VBA Code:
Private Function FieldsValidated() As Boolean
    If Combobox1 = "Reason 1" Or Combobox1 = "Reason 2" Then
        If Combobox2 = vbNullString Then Exit Function
    End If
    FieldsValidated = True
End Function

Private Sub cmd1_Click()
    If Not FieldsValidated Then msgBox "Message"
End Sub
 
Upvote 0

Forum statistics

Threads
1,214,918
Messages
6,122,255
Members
449,075
Latest member
staticfluids

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