How to trap an error (and force a choice)?

bluegno

Registered User.
Local time
, 17:38
Joined
Nov 30, 2005
Messages
27
How do I programmatically force an error dialog to make a certain choice?

I'm able to trap the dialog via the following code:

Code:
Private Sub Form_Error(DataErr As Integer, Response As Integer)
  If DataErr = 7787 Then  'record updated by another "user" (subform)
    MsgBox "Error trapped!"
    Response = acDataErrContinue
  Else
    Response = acDataErrDisplay
  End If
End Sub

Problem is, if I bypass the 7787 error in this manner, it defaults to dropping the changes, rather than saving the record, which is what I want. (Both are choices on the dialog.)

Any help would be most appreciated.
 
DoCmd.Save doesn't help

I should have mentioned... if I replace the MsgBox line below with "DoCmd.Save", the updates to the record still get thrown away.

bluegno said:
How do I programmatically force an error dialog to make a certain choice?

I'm able to trap the dialog via the following code:

Code:
Private Sub Form_Error(DataErr As Integer, Response As Integer)
  If DataErr = 7787 Then  'record updated by another "user" (subform)
    MsgBox "Error trapped!"
    Response = acDataErrContinue
  Else
    Response = acDataErrDisplay
  End If
End Sub

Problem is, if I bypass the 7787 error in this manner, it defaults to dropping the changes, rather than saving the record, which is what I want. (Both are choices on the dialog.)

Any help would be most appreciated.
 
"DoCmd.Save" does not save the current record, it save the db object [form, report, etc].

This the correct command to save the current record...

DoCmd.RunCommand acCmdSaveRecord
 
acCmdSaveRecord

Thanks, I appreciate the response! Good info.

I couldn't fool it though. When that line of code gets hit, I get "Run-time error '2115': The macro or function set to the BeforeUpdate or ValidationRule property for this field is preventing the tool from saving the data in the field."

But if I don't trap the error, and manually select the "Save Record" button in the dialog, everything seems to work fine. If only there were some way of not making the user hit the button every time....

ghudson said:
"DoCmd.Save" does not save the current record, it save the db object [form, report, etc].

This the correct command to save the current record...

DoCmd.RunCommand acCmdSaveRecord
 
You can not put a acCmdSaveRecord command in a before update event. The before update event is used to validate and then cancel the event if the validation fails your test.
 
acCmdSaveRecord

Hmmm, that's close. The acCmdSaveRecord is called inside Form_Error which is hit between the BeforeUpdate and the AfterUpdate events. So that would pretty much be the Update itself(?). For what it's worth, we're using ADO w/ a SQL Server back end.

You have been kind to respond to my questions. If you are feeling especially philanthropic, perhaps you would take a gander at my original post ("Problem updating main form control from subform"), to which, sadly, nobody has responded.

Basically, the problem is our Access 2000 tool broke when we upgraded to Office 2003. I keep thinking there has to be a simple fix, but so far, it has eluded me.

ghudson said:
You can not put a acCmdSaveRecord command in a before update event. The before update event is used to validate and then cancel the event if the validation fails your test.
 
How did the previous version break? I have had really good luck with just adding the necessary libraries after upgrading to 2003.
 
Oh, maybe I wasn't clear. When I said the tool broke, I was referring to my original post (per the preceding paragraph). This is the one you originally responded to.

In other words, I was saying the "record changed by another user" problem (that you and I both experienced) caused my tool to stop working.
 

Users who are viewing this thread

Back
Top Bottom