Form with multiple fields required before update

Collapse
X
 
  • Time
  • Show
Clear All
new posts
  • clloyd
    New Member
    • Mar 2008
    • 91

    Form with multiple fields required before update

    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

    Code:
    If Me![CategoryName] = "Travel" Then
      If IsNull(Me![ClientNumber]) Then
        MsgBox "You must provide a Client Number to use this category"
        Me![LocNo].SetFocus
          Cancel = True
            Exit Sub
      End If
    Can anyone help?
  • PianoMan64
    Recognized Expert Contributor
    • Jan 2008
    • 374

    #2
    If you simply put the code in the form_Beforeupda te event, then you simply put in If statements for all three conditions to test before the record can be saved.

    Example:

    Code:
    Private Sub Form_BeforeUpdate(Cancel as Integer)
    
    If me.fieldname1 = "Some Value" Then
    	 'do something here
    else
    	 'do something here
    	  cancel = true
    end if
    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.

    Comment

    • clloyd
      New Member
      • Mar 2008
      • 91

      #3
      It worked fine. Thanks

      Comment

      Working...