Results 1 to 3 of 3
  1. #1
    Evans2 is offline Novice
    Windows Vista Access 2010 32bit
    Join Date
    Jul 2014
    Location
    Seattle
    Posts
    27

    Help with multiple ElseIf statement

    Hi all,

    I've got a bit of VBA code that looks at a field cboCompanyID in my form and if that field is blank is left blank and the user tries to save, they get a message saying "Please Enter a Customer"
    ElseIf Me.cboCompanyID = "" Or IsNull(Me.cboCompanyID) Then
    MsgBox "Please Enter a Customer", vbInformation, "Incomplete Data"
    Me.cboCompanyID.SetFocus
    Exit Sub
    Else


    DoCmd.RunCommand acCmdSaveRecord

    Now I've created another field, Me.cboTargetCustomer as an alternative option. What I'm aiming for is for users to choose between the two fields. They would only get the "Please Enter a Customer" message if both fields are left blank.

    My attempt below is not doing what I need. If one of the fields is blank but the other isn't, the message still pops up.
    ElseIf Me.cboCompanyID = "" Or IsNull(Me.cboCompanyID) And Me.cboTargetCustomer = "" Or IsNull(Me.cboTargetCustomer) Then
    MsgBox "Please Enter a Customer", vbInformation, "Incomplete Data"
    Me.cboCompanyID.SetFocus
    Exit Sub
    Else
    DoCmd.RunCommand acCmdSaveRecord

    Any help is appreciated.

    Thank you

  2. #2
    andy49's Avatar
    andy49 is offline VIP
    Windows 10 Access 2010 64bit
    Join Date
    Nov 2016
    Location
    London
    Posts
    1,051
    Code:
    ElseIf (Me.cboCompanyID = "" Or IsNull(Me.cboCompanyID)) And (Me.cboTargetCustomer = "" Or IsNull(Me.cboTargetCustomer)) Then

  3. #3
    Evans2 is offline Novice
    Windows Vista Access 2010 32bit
    Join Date
    Jul 2014
    Location
    Seattle
    Posts
    27
    Perfecto! Thanks

Please reply to this thread with any new information or opinions.

Similar Threads

  1. Replies: 10
    Last Post: 10-11-2016, 02:39 AM
  2. Help with If...Then...ElseIf
    By willmafingerdo in forum Programming
    Replies: 2
    Last Post: 09-23-2016, 08:15 AM
  3. Automate data input with If, Elseif Statement
    By Exmark1 in forum Programming
    Replies: 4
    Last Post: 02-19-2015, 09:52 AM
  4. If then Elseif then....
    By Thompyt in forum Programming
    Replies: 3
    Last Post: 10-27-2014, 01:31 PM
  5. Replies: 5
    Last Post: 03-03-2013, 07:18 AM

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts
  •  
Other Forums: Microsoft Office Forums