By using this site, you agree to our updated Privacy Policy and our Terms of Use. Manage your Cookies Settings.
424,503 Members | 2,730 Online
Bytes IT Community
+ Ask a Question
Need help? Post your question and get tips & solutions from a community of 424,503 IT Pros & Developers. It's quick & easy.

Form with multiple fields required before update

P: 93
I have a form that based on the category the user chooses three fields are required information that they must input or the record is incomplete. I also want to display a unique message if they do not put data in the field.

The following works for one field but there are two additional fields that I require. For example PO# and Date

Expand|Select|Wrap|Line Numbers
  1.  
  2. If Me![CategoryName] = "Travel" Then
  3.   If IsNull(Me![ClientNumber]) Then
  4.     MsgBox "You must provide a Client Number to use this category"
  5.     Me![LocNo].SetFocus
  6.       Cancel = True
  7.         Exit Sub
  8.   End If
  9.  
  10.  
Can anyone help?
Jul 24 '08 #1
Share this Question
Share on Google+
2 Replies


Expert 100+
P: 374
If you simply put the code in the form_Beforeupdate event, then you simply put in If statements for all three conditions to test before the record can be saved.

Example:

Expand|Select|Wrap|Line Numbers
  1. Private Sub Form_BeforeUpdate(Cancel as Integer)
  2.  
  3. If me.fieldname1 = "Some Value" Then
  4.      'do something here
  5. else
  6.      'do something here
  7.       cancel = true
  8. end if
  9. If me.fieldname2 = "Some value" Then '... and so on
  10.  
that way you can check every value on the form before the record is saved.

Hope that helps,

Joe P.
Jul 25 '08 #2

P: 93
It worked fine. Thanks
Jul 25 '08 #3

Post your reply

Sign in to post your reply or Sign up for a free account.