I have this simple Access Form that when you fill out the form and forget to fill out the Business Unit field, a msgBox will pop up telling you so and setFocus to that very Combo box. If it is Not null, I want to call the next feature. The first part of this code works, but the when it is notNull it wil not carry on.
Private Sub Image_AddNon_RPS_Button_Click()
If IsNull(Me.BU_Selected_Add) Then
MsgBox "Please Select a Business Unit!", vbOKOnly
Exit Sub
End If
Me.Combo_BU_Selector.SetFocus
Exit Sub
If Not IsNull(Me.BU_Selected_Add) Then
Call Add_RPS_LINE
End If
End Sub
Does anybody see where I am totally out in left field?
You've got an extra Exit Sub (the one after the first MsgBox) that stops your code from doing what you want. Also, your first End If is in the wrong location.
Try something like this instead:
Private Sub Image_AddNon_RPS_Button_Click()
If IsNull(Me.BU_Selected_Add) Then ' No business unit
MsgBox "Please Select a Business Unit!", vbOKOnly ' Tell user
Me.Combo_BU_Selector.SetFocus ' Focus the control
Exit Sub ' Exit the method
End If ' End the IsNull test
Call Add_RPS_LINE ' You only get here if the above doesn't execute
End Sub
It helps if you learn to properly indent your code to match If and End If visually, so you can see where they line up (match) and where they don't. :-)
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With