Stop update event in ACCESS 2003

I need to have the update stopped if the user has not completed the date when trying to update the country field I get the attached error message.  So, how do I stop in the before update event data entry and move the focus to another field?
Private Sub cboCountry_BeforeUpdate(Cancel As Integer)
    If IsNull(Me.txtDate) Or Me.txtDate = "" Then
        MsgBox "Please enter open date first prior to " & vbCrLf & _
               "selecting a country.  Temp Number assignment " & vbCrLf & _
               "requires this data entry sequence.", vbOKOnly
        Me.cboCountry.Value = ""
        Me.txtDate.SetFocus
        Exit Sub
    End If
End Sub

Open in new window

ErrorMessage.jpg
Sandra SmithRetiredAsked:
Who is Participating?

[Product update] Infrastructure Analysis Tool is now available with Business Accounts.Learn More

x
I wear a lot of hats...

"The solutions and answers provided on Experts Exchange have been extremely helpful to me over the last few years. I wear a lot of hats - Developer, Database Administrator, Help Desk, etc., so I know a lot of things but not a lot about one thing. Experts Exchange gives me answers from people who do know a lot about one thing, in a easy to use platform." -Todd S.

lee555J5Commented:
See "Cancel As Integer" in the sub declaration. That is a fake boolean (it says integer) that is checked in this event. Change "Exit Sub" to "Cancel = True".
Lee
0
lee555J5Commented:
Cancel initializes to 0. If your data validation condition is executed, make Cancel equal something other than 0, such as True (-1).
Lee
0
DatabaseMX (Joe Anderson - Microsoft Access MVP)Database Architect / Systems AnalystCommented:
You can't do this in a Before Update event:

Me.cboCountry.Value = ""

You are trying to change the value and that is not allowed in a BU event.  Maybe you want this:

Private Sub cboCountry_BeforeUpdate(Cancel As Integer)
    If IsNull(Me.txtDate) Or Me.txtDate = "" Then
        MsgBox "Please enter open date first prior to " & vbCrLf & _
               "selecting a country.  Temp Number assignment " & vbCrLf & _
               "requires this data entry sequence.", vbOKOnly
        Me.cboCountry.UNDO
       Cancel = True
           'Me.txtDate.SetFocus  ' Can't do this either
        Exit Sub
    End If
End Sub
0

Experts Exchange Solution brought to you by

Your issues matter to us.

Facing a tech roadblock? Get the help and guidance you need from experienced professionals who care. Ask your question anytime, anywhere, with no hassle.

Start your 7-day free trial
Sandra SmithRetiredAuthor Commented:
Ok, seems the best I can achieve is at least create a message.  I will have to think about how to create the auto-generated ID as the ID is based on the date and country.  Will have to so a little shifting.  I think you both were pointing the same direction, but DatabaseMX's was easiest as I just plunked it into my code and it worked.
Thank you both.
0
It's more than this solution.Get answers and train to solve all your tech problems - anytime, anywhere.Try it for free Edge Out The Competitionfor your dream job with proven skills and certifications.Get started today Stand Outas the employee with proven skills.Start learning today for free Move Your Career Forwardwith certification training in the latest technologies.Start your trial today
Microsoft Access

From novice to tech pro — start learning today.