Results 1 to 10 of 10
  1. #1
    2 Star Lounger
    Join Date
    Aug 2002
    Location
    Minneapolis, MN, Minnesota
    Posts
    162
    Thanks
    1
    Thanked 0 Times in 0 Posts

    Message Box Errors (Access 2000)

    I have a form that opens and the cursor is set on the field EmployeeID.
    I would like a message box to appear that states; "PLEASE ENTER AN EMPLOYEE ID", if the user tries to move to another field without selecting an Employee ID. This message box should continue to appear until the user either enters an ID number or exits the form.

    This is the code that I have in the LostFocus event:

    'This checks if Employee ID field is empty'
    If IsNull([EmployeeID]) Then
    MsgBox "PLEASE ENTER AN EMPLOYEE ID!"
    Exit Sub
    End If

    End Sub

    The message box appears, but once I click on "OK" it lets me move on the the next field. What can I insert to accomplish what I want? Thanks
    Easy Access

  2. #2
    Super Moderator
    Join Date
    Aug 2001
    Location
    Evergreen, CO, USA
    Posts
    6,623
    Thanks
    3
    Thanked 60 Times in 60 Posts

    Re: Message Box Errors (Access 2000)

    You need to set focus back to the combo box - that's what the LostFocus event means. You could also enforce this with a validation statement that says the field can't be null, and it wouldn't involve any code. You might want to look at the of the tutorial books for some of the tricks in setting up validation of data on a form, as there are many alternatives.
    Wendell

  3. #3
    Platinum Lounger
    Join Date
    Dec 2001
    Location
    Melbourne, Australia
    Posts
    4,594
    Thanks
    0
    Thanked 27 Times in 27 Posts

    Re: Message Box Errors (Access 2000)

    Put your code in the BeforeUpdate of the combo box and set Cancel = True if it's null, this will hold the operator in the combo box until you actually select something.
    HTH
    Pat <img src=/S/cheers.gif border=0 alt=cheers width=30 height=16>

  4. #4
    2 Star Lounger
    Join Date
    Aug 2002
    Location
    Minneapolis, MN, Minnesota
    Posts
    162
    Thanks
    1
    Thanked 0 Times in 0 Posts

    Re: Message Box Errors (Access 2000)

    This is the code in the BeforeUpdate event of combo box EmployeeID

    Private Sub EmployeeID_BeforeUpdate(Cancel As Integer)
    'This checks if Employee ID field is not empty'
    If IsNull([EmployeeID]) Then
    MsgBox "PLEASE ENTER AN EMPLOYEE ID!"
    Exit Sub

    End If

    End Sub

    Where do I set "Cancel = True" in this procedure?
    Easy Access

  5. #5
    Platinum Lounger
    Join Date
    Dec 2001
    Location
    Melbourne, Australia
    Posts
    4,594
    Thanks
    0
    Thanked 27 Times in 27 Posts

    Re: Message Box Errors (Access 2000)

    Just after the MsgBox command.
    Pat <img src=/S/cheers.gif border=0 alt=cheers width=30 height=16>

  6. #6
    2 Star Lounger
    Join Date
    Aug 2002
    Location
    Minneapolis, MN, Minnesota
    Posts
    162
    Thanks
    1
    Thanked 0 Times in 0 Posts

    Re: Message Box Errors (Access 2000)

    Hey Patti,
    I tried that and it works great.
    I have one small problem. I have an Exit command button to close the form. The message box code won't let me exit until I pick an employee ID.
    How do I get the form to let me use the Exit command button??? <img src=/S/confused.gif border=0 alt=confused width=15 height=20>
    Easy Access

  7. #7
    Platinum Lounger
    Join Date
    Dec 2001
    Location
    Melbourne, Australia
    Posts
    4,594
    Thanks
    0
    Thanked 27 Times in 27 Posts

    Re: Message Box Errors (Access 2000)

    Firstly I'm Pat not Patti.
    Second, I missed the significance of the exit the form requirement.
    What you will have to do is to delete the code in the EmployeeID_BeforeUpdate event, and put the following code in a GotFocus event of all the controls on the form except your exit button and the EmployeeID control.

    Private Sub XXXXXXX_GotFocus()
    If IsNull(EmployeeID) Then
    EmployeeID.SetFocus
    End If
    End Sub

    Be sure to substitute the XXXXXXX with your control names.
    HTH
    Pat <img src=/S/cheers.gif border=0 alt=cheers width=30 height=16>

  8. #8
    5 Star Lounger
    Join Date
    Jul 2002
    Location
    Toronto, Ontario, Canada
    Posts
    1,139
    Thanks
    0
    Thanked 0 Times in 0 Posts

    Re: Message Box Errors (Access 2000)

    An easier way would be to put this at the start of the Exit Button code:
    <pre>If Me.Dirty = True Then
    Me.Undo
    End If</pre>

    This will undo any changes to the bound data and not force a save.
    --
    Bryan Carbonnell - Toronto <img src=/S/flags/Ontario.gif border=0 alt=Ontario width=30 height=18> <img src=/S/flags/Canada.gif border=0 alt=Canada width=30 height=18>
    Unfortunately common sense isn't so common!!
    Visit my website for useful Word, Excel and Access code, templates and Add-Ins

  9. #9
    Platinum Lounger
    Join Date
    Dec 2001
    Location
    Melbourne, Australia
    Posts
    4,594
    Thanks
    0
    Thanked 27 Times in 27 Posts

    Re: Message Box Errors (Access 2000)

    That's correct if he does not want to save the record on exit, however, he wants to make sure that an EmployeeID has been chosen before being allowed into any other control excluding the exit button (he wants to be able to exit the form when he has NOT chosen an EmployeeID).
    Pat <img src=/S/cheers.gif border=0 alt=cheers width=30 height=16>

  10. #10
    2 Star Lounger
    Join Date
    Aug 2002
    Location
    Minneapolis, MN, Minnesota
    Posts
    162
    Thanks
    1
    Thanked 0 Times in 0 Posts

    Re: Message Box Errors (Access 2000)

    Thanks for all your help Patt, <img src=/S/bow.gif border=0 alt=bow width=15 height=15>
    Easy Access

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts
  •