Results 1 to 9 of 9
  1. #1
    2 Star Lounger
    Join Date
    Oct 2002
    Location
    Lakewood, New Jersey, USA
    Posts
    187
    Thanks
    0
    Thanked 0 Times in 0 Posts

    Rid me of Access error msgs (2002)

    Whenever I write validation code in a beforeUpdate event, and set Cancel to true, I get an Access error message when I try to close the object telling me that it couldn't save the object and do I want to close it anyway. I don't want my users to see this message as it will simply confuse them. How do I disable it?

  2. #2
    Plutonium Lounger
    Join Date
    Dec 2000
    Location
    Sacramento, California, USA
    Posts
    16,775
    Thanks
    0
    Thanked 1 Time in 1 Post

    Re: Rid me of Access error msgs (2002)

    Don't try and hide it, try and figure out why you're getting it. You have created a situation where you are making a change to the design of the form, not to the data. Otherwise, you would not be getting that message. Since your users shouldn't be changing the design of the form, you need to figure out what you're doing wrong. Why don't you post a sample of your BeforeUpdate code and perhaps someone can explain what exactly is happening. In general, hiding messages like that is a good way to build problems into your application.
    Charlotte

  3. #3
    Gold Lounger
    Join Date
    Jun 2001
    Location
    Crystal Beach, FL, Florida, USA
    Posts
    3,436
    Thanks
    1
    Thanked 34 Times in 34 Posts

    Re: Rid me of Access error msgs (2002)

    Are you sure you are not getting a message that it couldn't save a Record? This would happen if your form was dirty and then you tried to exit the form, but Access couldn't write/update the current record because of code in the BeforeUpdate event that kept canceling the write.
    Mark Liquorman
    See my website for Tips & Downloads and for my Liquorman Utilities.

  4. #4
    2 Star Lounger
    Join Date
    Oct 2002
    Location
    Lakewood, New Jersey, USA
    Posts
    187
    Thanks
    0
    Thanked 0 Times in 0 Posts

    Re: Rid me of Access error msgs (2002)

    Here is some code in which I set Cancel=true:

    Private Sub Form_BeforeUpdate(Cancel As Integer)
    If Not IsNull(Me.Text177) Then
    If (IsNull(Me.Combo179) And Not IsNull(Me.Text186)) Then
    MsgBox "You must select a name in order to save this contact.", vbExclamation, "My Title"
    Cancel = True
    ElseIf (IsNull(Me.Text186) And Not IsNull(Me.Combo179)) Then
    MsgBox "You must enter a name in order to save this contact.", vbExclamation, "My Title"
    Cancel = True
    End If
    End If
    End Sub

    I don't know where I am changing the design of the form in this code. I thought this message was Access's way of telling the user that the update was cancelled and his data will therefore not be saved. I don't want access to tell my users that, I want to tell them myself in terms they'll understand.

  5. #5
    2 Star Lounger
    Join Date
    Oct 2002
    Location
    Lakewood, New Jersey, USA
    Posts
    187
    Thanks
    0
    Thanked 0 Times in 0 Posts

    Re: Rid me of Access error msgs (2002)

    You're right, Mark. I'm sorry. THe message was that it couldn't save the data (ie. the record). What does it mean that the form is dirty - that it has data on it? How can I validate my user data before they close the form and avoid this message?

  6. #6
    Plutonium Lounger
    Join Date
    Dec 2000
    Location
    Sacramento, California, USA
    Posts
    16,775
    Thanks
    0
    Thanked 1 Time in 1 Post

    Re: Rid me of Access error msgs (2002)

    It means that your user has entered or changed a value in that record. Using the BeforeUpdate of the *form* cancels the write. However, you haven't applied a Me.Undo to rollback the changes to the record, so closing the form keeps tripping over a dirty record that can't be saved because of the missing information and the Cancel you issued in the BeforeUpdate event.
    Charlotte

  7. #7
    2 Star Lounger
    Join Date
    Oct 2002
    Location
    Lakewood, New Jersey, USA
    Posts
    187
    Thanks
    0
    Thanked 0 Times in 0 Posts

    Re: Rid me of Access error msgs (2002)

    Oh, okay. Thanks a lot, Charlotte! When you learn on the job, it's so easy to miss essential bits and pieces like doing a me.undo after cancelling an update. I'm glad the solution is so simple. <img src=/S/bravo.gif border=0 alt=bravo width=16 height=30>

  8. #8
    Gold Lounger
    Join Date
    Jun 2001
    Location
    Crystal Beach, FL, Florida, USA
    Posts
    3,436
    Thanks
    1
    Thanked 34 Times in 34 Posts

    Re: Rid me of Access error msgs (2002)

    The "dirty" property of a bound form means that the user has altered the data on the form; either changing existing data or starting a new record. Any keystroke into a bound control will set the form as dirty. When the user tries to exit the form, Access writes the current record if the form is dirty. In your case, your code in the BeforeUpdate event cancels the write, so Access is in a quandry and tells you. This is an important message, so you don't want to skip it. It tells the user that any changes will be lost if they continue on and close the form.

    On way to handle this more gracefully is to remove the Windows Close button on the form and create your own Close command button. You could then run your validity checks here and if it fails, offer user choice of closing anyway (in which case you would use the Me.Undo to cancel changes).
    Mark Liquorman
    See my website for Tips & Downloads and for my Liquorman Utilities.

  9. #9
    2 Star Lounger
    Join Date
    Oct 2002
    Location
    Lakewood, New Jersey, USA
    Posts
    187
    Thanks
    0
    Thanked 0 Times in 0 Posts

    Re: Rid me of Access error msgs (2002)

    tHANKS Mark. That's exactly what I'll do.

Posting Permissions

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