By using this site, you agree to our updated Privacy Policy and our Terms of Use. Manage your Cookies Settings.
435,197 Members | 1,151 Online
Bytes IT Community
+ Ask a Question
Need help? Post your question and get tips & solutions from a community of 435,197 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
  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
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.


Expand|Select|Wrap|Line Numbers
  1. Private Sub Form_BeforeUpdate(Cancel as Integer)
  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
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.