Hello,
(A few days ago I asked this question but the suggestion I got back did not work)
I want to validate a form to make sure all the required information is filled out by the user before going to another record or exiting the form all together.
The suggestion I received was to write code in the before update.
I tried that suggestion but either I did it wrong or it didn't work.
I am alittle unsure of where I am meant to write the code. In the before update of the text box or in the form?
If someone wouldn't mind helping me I could really use the help.
And if it is not to much to ask would you be able to write the code for me.
One of the text boxes that I want to validate is "Order #". The name of the text box is txtOrderId.
I want to prompt the user with a msgbox saying "You must enter an Order number before leaving this form"
Then set focus back to the txtOrderId
***************************************
Here's what I wrote
Private Sub Form_BeforeUpdate(Cancel As Integer)
If txtOrderId = Null Then
MsgBox "You Must enter a valid Order Number"
End If
txtOrderId.SetFocus
End Sub
****************************************
Am I even going in the right direction?
Thanks,
Peter Vav
(A few days ago I asked this question but the suggestion I got back did not work)
I want to validate a form to make sure all the required information is filled out by the user before going to another record or exiting the form all together.
The suggestion I received was to write code in the before update.
I tried that suggestion but either I did it wrong or it didn't work.
I am alittle unsure of where I am meant to write the code. In the before update of the text box or in the form?
If someone wouldn't mind helping me I could really use the help.
And if it is not to much to ask would you be able to write the code for me.
One of the text boxes that I want to validate is "Order #". The name of the text box is txtOrderId.
I want to prompt the user with a msgbox saying "You must enter an Order number before leaving this form"
Then set focus back to the txtOrderId
***************************************
Here's what I wrote
Private Sub Form_BeforeUpdate(Cancel As Integer)
If txtOrderId = Null Then
MsgBox "You Must enter a valid Order Number"
End If
txtOrderId.SetFocus
End Sub
****************************************
Am I even going in the right direction?
Thanks,
Peter Vav
Last edited: