Results 1 to 12 of 12
  1. #1
    pjs101974 is offline Novice
    Windows 7 64bit Access 2010 64bit
    Join Date
    Nov 2012
    Posts
    6

    Message box based on one combo box populated and another combo box blank

    Hello,

    I am hoping that someone out there can steer me in the right
    direction.

    Here is the scenario:

    I have a main form and a subform
    within it. The subform contains two combo boxes:

    cboUnitDefects (contains
    multiple options to describe product failures)
    cboFailureLocation (contains


    multiple options to define a physical location)

    What I am looking to do
    is:
    If cboUnitDefects is populated AND cboFailureLocation is
    not
    , a message box requiring the population of cboFailureLocation comes up
    and tells the operator to select a failure location. So far, the following code
    was used with no success within the subform's "Before Update"
    property:

    Private Sub Form_BeforeUpdate(Cancel As Integer)
    If
    (Len(Me.cboFailure_Location & vbNullString) = False) And
    (Len(Me.cboUnitDefects & vbNullString) = True) Then
    MsgBox "Please Enter
    a Failure Location", vbOKOnly
    Cancel = True
    End If
    End Sub

    Thank
    you for your help in advance!
    --Phill

  2. #2
    pbaldy's Avatar
    pbaldy is offline Who is John Galt?
    Windows XP Access 2007
    Join Date
    Feb 2010
    Location
    Nevada, USA
    Posts
    22,521
    Does this work?

    If Len(Me.cboFailure_Location & vbNullString) = 0 And Len(Me.cboUnitDefects & vbNullString) > 0 Then
    Paul (wino moderator)
    MS Access MVP 2007-2019
    www.BaldyWeb.com

  3. #3
    pjs101974 is offline Novice
    Windows 7 64bit Access 2010 64bit
    Join Date
    Nov 2012
    Posts
    6
    Hi Paul,

    Thank you for your help on this! That did the trick and it works if the user tries to close the form. The only other issue is that if a user tries to add another record, the message will come up, but a "run time error 2105" is displayed. Is there any way around this one?

    Thank you once again!!!

  4. #4
    pbaldy's Avatar
    pbaldy is offline Who is John Galt?
    Windows XP Access 2007
    Join Date
    Feb 2010
    Location
    Nevada, USA
    Posts
    22,521
    What is the text of that one? What is the sequence of events?
    Paul (wino moderator)
    MS Access MVP 2007-2019
    www.BaldyWeb.com

  5. #5
    pjs101974 is offline Novice
    Windows 7 64bit Access 2010 64bit
    Join Date
    Nov 2012
    Posts
    6
    Hi Paul,

    The text states: Run Time Error 2105: "you can't go to the specified record"

    The sequence of events is:
    1: The operator makes a selection in cboUnitDefects.
    2: Instead of selecting a failure location using cboFailure_Location, the operator simply clicks a command button which is set up to go to a new record.

    Is there a possibility of having the focus go to the cbo rather than displaying the error?

  6. #6
    pbaldy's Avatar
    pbaldy is offline Who is John Galt?
    Windows XP Access 2007
    Join Date
    Feb 2010
    Location
    Nevada, USA
    Posts
    22,521
    I think the before update code is stopping the update, which won't allow the form to go to a different record. You could put the same test there.
    Paul (wino moderator)
    MS Access MVP 2007-2019
    www.BaldyWeb.com

  7. #7
    pjs101974 is offline Novice
    Windows 7 64bit Access 2010 64bit
    Join Date
    Nov 2012
    Posts
    6
    Hi Paul,

    Doing that one still produces the same results. I even tried it in the "Before Update" event.

  8. #8
    pbaldy's Avatar
    pbaldy is offline Who is John Galt?
    Windows XP Access 2007
    Join Date
    Feb 2010
    Location
    Nevada, USA
    Posts
    22,521
    What's the code behind the button now? You want to abort if the combo test isn't met.
    Paul (wino moderator)
    MS Access MVP 2007-2019
    www.BaldyWeb.com

  9. #9
    pjs101974 is offline Novice
    Windows 7 64bit Access 2010 64bit
    Join Date
    Nov 2012
    Posts
    6
    Quote Originally Posted by pbaldy View Post
    What's the code behind the button now? You want to abort if the combo test isn't met.
    Hi paul,

    Here is the code behind the button:

    Private Sub cmdAddIssue_Click()
    If Len(Me.cboFailure_Location & vbNullString) = 0 And Len(Me.cboUnitDefects & vbNullString) > 0 Then
    MsgBox "PLEASE ENTER A FAILURE LOCATION - MTP, ESS, OR ATP", vbOKOnly, ""
    Cancel = True
    End If
    DoCmd.GoToRecord , , acNewRec
    End Sub

  10. #10
    pbaldy's Avatar
    pbaldy is offline Who is John Galt?
    Windows XP Access 2007
    Join Date
    Feb 2010
    Location
    Nevada, USA
    Posts
    22,521
    That lets the GoToRecord happen no matter what. You want:

    Private Sub cmdAddIssue_Click()
    If Len(Me.cboFailure_Location & vbNullString) = 0 And Len(Me.cboUnitDefects & vbNullString) > 0 Then
    MsgBox "PLEASE ENTER A FAILURE LOCATION - MTP, ESS, OR ATP", vbOKOnly, ""
    Else
    DoCmd.GoToRecord , , acNewRec
    End If
    End Sub
    Paul (wino moderator)
    MS Access MVP 2007-2019
    www.BaldyWeb.com

  11. #11
    pjs101974 is offline Novice
    Windows 7 64bit Access 2010 64bit
    Join Date
    Nov 2012
    Posts
    6
    Quote Originally Posted by pbaldy View Post
    That lets the GoToRecord happen no matter what. You want:

    Private Sub cmdAddIssue_Click()
    If Len(Me.cboFailure_Location & vbNullString) = 0 And Len(Me.cboUnitDefects & vbNullString) > 0 Then
    MsgBox "PLEASE ENTER A FAILURE LOCATION - MTP, ESS, OR ATP", vbOKOnly, ""
    Else
    DoCmd.GoToRecord , , acNewRec
    End If
    End Sub

    Paul, you nailed it! Thank you!!!!!!!

  12. #12
    pbaldy's Avatar
    pbaldy is offline Who is John Galt?
    Windows XP Access 2007
    Join Date
    Feb 2010
    Location
    Nevada, USA
    Posts
    22,521
    Happy to help!
    Paul (wino moderator)
    MS Access MVP 2007-2019
    www.BaldyWeb.com

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

Similar Threads

  1. Replies: 1
    Last Post: 10-30-2012, 10:29 AM
  2. Replies: 8
    Last Post: 02-19-2012, 03:48 PM
  3. Replies: 5
    Last Post: 12-14-2011, 02:37 PM
  4. Replies: 5
    Last Post: 01-02-2011, 10:09 AM
  5. Replies: 1
    Last Post: 01-21-2010, 02:36 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