If Null Error Message

  • Thread starter Thread starter Evie V via AccessMonster.com
  • Start date Start date
E

Evie V via AccessMonster.com

I have a text box with code that when the user enters a customer number, a
message pops up that they must also enter a company name if the company name
field is blank. How can I prevent the user from going any further if the
company name is blank.

Private Sub companynum_AfterUpdate()
If (IsNull(CompanyName)) Then
' If no Company Name selected, stop procedure
MsgBox "You Must Enter A Company Name"
Exit Sub
End If
End Sub

Thanks,
Evie
 
Evie V via AccessMonster.com wrote in message
I have a text box with code that when the user enters a customer number, a
message pops up that they must also enter a company name if the company name
field is blank. How can I prevent the user from going any further if the
company name is blank.

Private Sub companynum_AfterUpdate()
If (IsNull(CompanyName)) Then
' If no Company Name selected, stop procedure
MsgBox "You Must Enter A Company Name"
Exit Sub
End If
End Sub

Thanks,
Evie


Try placing the code in the before update event of the control in
stead.
Then in stead of Exit Sub, use Cancel = True.

Though the safest event to use for validation, would be the before
update event of the form.
 
Move your code to the Exit event of the Company Name text box and add the line:
Cancel = True
Just before the Exit Sub.
 
You can try using the form_beforeupdate event. If the company name has not
been entered then give your message and set the cancel parameter to true.
 
Back
Top