Sign In | Register Now About Bytes | Help | Site Map
Connecting Tech Pros Worldwide

Form with multiple fields required before update

Question posted by: clloyd (Member) on July 24th, 2008 06:10 PM
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.  


Can anyone help?
PianoMan64's Avatar
PianoMan64
Expert
275 Posts
July 25th, 2008
06:06 AM
#2

Re: Form with multiple fields required before update
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


that way you can check every value on the form before the record is saved.

Hope that helps,

Joe P.

Reply
clloyd's Avatar
clloyd
Member
56 Posts
July 25th, 2008
01:58 PM
#3

Re: Form with multiple fields required before update
It worked fine. Thanks

Reply
Reply
Not the answer you were looking for? Post your question . . .
189,798 Experts ready to help you find a solution.
Sign up for a free account, or Login (if you're already a member).

Latest Articles: Read & Comment
Top Microsoft Access / VBA Forum Contributors