Tek-Tips is the largest IT community on the Internet today!

Members share and learn making Tek-Tips Forums the best source of peer-reviewed technical information on the Internet!

  • Congratulations Mike Lewis on being selected by the Tek-Tips community for having the most helpful posts in the forums last week. Way to Go!

Message boxes 1

Status
Not open for further replies.

ptrifile

Technical User
Aug 10, 2004
457
US
I use the following code in my save button for an instance when a user fails to populate a field so they will go back and fill in the field:

If (IsNull(Company)) Then
MsgBox "Please Choose a Company Name", vbExclamation
Cancel = True

this works fine for one field however when i do the following it still only checks the first one, can someone tell me the proper way to write this so that I can get more than one field to be recognized:

If (IsNull(Company)) Then
MsgBox "Please Choose a Company Name", vbExclamation
Cancel = True

If (IsNull(Quantity)) Then
MsgBox "Please Enter the Quantity", vbExclamation
Cancel = True
End If

thank you!!!

Paul


 
Where is the End If corresponding to your first If ?

Hope This Helps, PH.
Want to get great answers to your Tek-Tips questions? Have a look at FAQ219-2884 or FAQ181-2886
 
PHV, I did have that in there, I was playing around trying different things, if i have the end if there it only recognizes the first part of the code and then doesnt pop up the message if there is nothing in the "QUANTITY" field, its like it skips right over it.

Thanks for the help!
Paul
 
How are ya ptrifile . . . . .

Try this:
Code:
[blue]   If (IsNull(Company)) Then
      MsgBox "Please Choose a Company Name", vbExclamation
      Cancel = True
      exit sub
   ElseIf (IsNull(Quantity)) Then
      MsgBox "Please Enter the Quantity", vbExclamation
      Cancel = True
   End If[/blue]

Calvin.gif
See Ya! . . . . . .
 
Exit Sub and ElseIf!!!!!! BRILLIANT!!!!!!!!!!

Theaceman1 your a lifesaver! thank you!!!!
 
You might want to enhance your code by giving the control that was empty back the focus. I also noticed that you where using unnecessary (IsNull(Company)), the line can be writen as shown below since the syntax for the IsNull is IsNull(Expression to be checked) and the If Then statement does not have a set ot () in the syntax

If IsNull(Company) Then
MsgBox "Please Choose a Company Name", vbExclamation
Cancel = True
Company.SetFocus
exit sub
ElseIf IsNull(Quantity) Then
MsgBox "Please Enter the Quantity", vbExclamation
Quantity.SetFocus
Cancel = True
End If
 
Status
Not open for further replies.

Part and Inventory Search

Sponsor

Back
Top