Tek-Tips is the largest IT community on the Internet today!

Members share and learn making Tek-Tips Forums the best source of peer-reviewed technical information on the Internet!

  • Congratulations IamaSherpa on being selected by the Tek-Tips community for having the most helpful posts in the forums last week. Way to Go!

Adding/SavingCancelling a record on a bound Form 1

Status
Not open for further replies.

robbob

Programmer
Oct 28, 2000
5
AU
Hi

I'm just wondering wether or not theres another way to save records on a form, besides using the Access menu items, record selectors, or DoCmd.RunCommand/DoCmd.DoMenuItem.

The reason I wish to know this is because, currently when if I press my custom save button that executes, DoCmd.RunCommand, and there happens to be a write conflict, then I get an error (2501), saying the DoCmd action was cencelled. This is really annoying, and the users dont understand it one bit.

I tried using the RecordSetClone.edit/addnew and update/cancel update but this doesnt seem to work in Access 97.

I dont want the users to have to select from a menu or click a record selectors. Anyone got any ideas. As I said, the problem with the DoCmd way, only becomes apparent if theres an error when saving the record, i.e Write Conflict.

Thanks

Robert Biernat
 
Try using:
DoCmd.RunCommand acCmdSaveRecord

Error 2501 is an error code that in generated by Access by canceling the operation. To get past this you need to add error handling to your code to capture the error.

This is just an example:

Private Sub YourSubName_TheEvent()
On Error GoTo Err_YourSubName

'***********************
'Place Your Code Here
'***********************

Exit_YourSubName:
Exit Sub

Err_YourSubName:
If Err.Number = 2501 Then
Resume Next
Else
MsgBox Err.Description
Resume Err_YourSubName
End If
End Sub

HTH :cool:
RDH

Ricky Hicks
rdhicks@mindspring.com

 
Nah that doesnt seem to work. I'll give you an idea of what I'm actually doin.

In the event handler for when the save button is pressed, I call a global method I've written called SaveCurrent which returns a boolean value, cause it actually does some checking of things. Its this function that calls the DoCmd.RunCommand acCmdSaveRecord


private sub btSave_Clicked
if SaveCurrent() then
Do some enabling of controls
endif
end sub

public SaveCurrent() as Boolean

SaveCurrent = false

if checkFields() then
DoCmd.RunCommand acCmdSaveRecord
do other stuff
SaveCurrent = true
endif
end function


Now, in the Form where the button is, I have in the OnError event handler soemthing like this:

Private Sub Form_Error(DataErr As Integer, Response As Integer)

If DataErr = 7787 Then 'Write Conflict
MsgBox "Your changes could not be saved." & vbCrLf & "Another user has updated the record", vbOKOnly, "Error saving changes"
Response = acDataErrContinue
End If

End Sub

After the response has been set, Run Time error 2501, saying the DoCmd has been cancelledd. I've tried placing "On Error" statements in both the Forms OnError, and the Global Function I wrote that executes the DoCmd statement.

I dont think what I want to be able to do is doable, but if you have any sugestionms iut would be appreciated.

Thjanks

Rob

 
Status
Not open for further replies.

Part and Inventory Search

Sponsor

Back
Top