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 TouchToneTommy on being selected by the Tek-Tips community for having the most helpful posts in the forums last week. Way to Go!

Before Update Question

Status
Not open for further replies.

jbh1378

Technical User
Dec 11, 2001
15
US
I am using this code given to me to update the tables only after the user is prompted to save. If the user hits no then the record is not entered in the tables. This works great BUT there are 3 or 4 subforms on this main form. Anytime a user clicks in a field in a subform, the user is prompted to save at that point. How can I get around this. I need it to act like the subform is part of the mainform.

This is the code used under the main form before update:

Dim ctl As Control

On Error GoTo Err_BeforeUpdate

' The Dirty property is True if the record has been changed.
If Me.Dirty Then
' Prompt to confirm the save operation.
If MsgBox("Do you want to save?", vbYesNo + vbQuestion, _
"Save Record") = vbNo Then
Me.Undo
End If
End If

Exit_BeforeUpdate:
Exit Sub

Err_BeforeUpdate:
MsgBox Err.Number & " " & Err.Description
Resume Exit_BeforeUpdate
 
Hmm... tricky one. There's no way to avoid updating the record on the main form when you click in a subform, but perhaps you can figure out a workaround.

Maybe try unbinding the form and inserting the data through DAO. That way, there's no record to save. Then, when your user hits the button, update the appropriate record(s) again using DAO. This could require some hefty coding, but I think it will solve your problem. Good luck!

--Ryan
 
Instead of using the code above on the form's before update, would something like the following work.
Upon closing the form, either by a button or by the x, a msgbox is diplayed asking whether the user wnats to save.
If the user clicks No, then there is code to undo that record?

 
Status
Not open for further replies.

Part and Inventory Search

Sponsor

Back
Top