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

Capturing Save on Subform with BeforeUpdate - Not? 1

Status
Not open for further replies.

catrey

Technical User
Feb 12, 2009
15
US
I have a problem similar to that in thread702-1453633 where user 'sheuz' was trying to "Provide the user with the option to save/undo changes made to the record in the form." The code I'm having trouble with is similar to sheuz's (myYesNoQPlus is a public function that simplifies creation of a message box so all that's needed is the statement text and any text for the title bar):

Code:
Private Sub Form_BeforeUpdate(Cancel As Integer)
If myYesNoQPlus("Changes have been made" & vbCrLf & _
"on this Professional." & vbCrLf & vbCrLf & _
"Do you want to save these changes?", "Changed Data!") = vbNo Then
    Undo            'undo changes
    Cancel = True   'cancel Save
Else
'Acess will automatically save the record
End If
End Sub

All over the internet and in numerous Access guides it's suggested to use code on BeforeUpdate to capture saves, but in thread702-1453633 it's basically said this is a bad idea and in essence doesn't work (I'm having trouble getting it to work - selecting 'No' in the message box doesn't stop data changes - even using all kinda reworking of the code -- for example everything in the record gets deleted with a recoding attempt using DoCmd.RunCommand acCmdUndo)

In thread702-1453633 alternate code is provided by user 'TheAceMan1'. He suggests:

Code:
Dim Msg As String, Style As Integer, Title As String, DL As String
   
   DL = vbNewLine & vbNewLine
   Msg = "Changes have been made to this record." & DL & _
         "Do you want to save these changes?"
   Style = vbQuestion + vbYesNo
   Title = "User Response Required! . . ."
   
   If MsgBox(Msg, Style, Title) = vbNo Then
      Cancel = True
      Me.Undo
   End If

But if BeforeUpdate isn't being used, what would make this code do anything? I may be using the wrong terms to express what I don't understand (I'm a sad noob) or I'm just ignorant for the same reason, but: what would trigger the message box using the above code -- which I guess is just typed into the form module somewhere? Clarification would be appreciated!



C. Reyes
 
How are ya catrey . . .
catrey said:
[blue]But if BeforeUpdate isn't being used, what would make this code do anything?[/blue]
To be sure, what I suggested was [blue]replacement code[/blue] for the [blue]Before Update[/blue] event.

[blue]Your Thoughts? . . .[/blue]

See Ya! . . . . . .

Be sure to see thread181-473997 [blue]Worthy Reading![/blue] [thumbsup2]
Also faq181-2886 [blue]Worthy Reading![/blue] [thumbsup2]
 
Okay... so your're saying the suggested code actually still uses the BeforeUpdate event and would go after:

Private Sub Form_BeforeUpdate(Cancel As Integer)

Sorry I'm so thick if this seems obvious....

C. Reyes
 
catrey . . .

Exactly! . . .

See Ya! . . . . . .

Be sure to see thread181-473997 [blue]Worthy Reading![/blue] [thumbsup2]
Also faq181-2886 [blue]Worthy Reading![/blue] [thumbsup2]
 
Thanks – code worked great!

C. Reyes
 
catrey . . .

BTW: Welcome to [blue]Tek-Tips![/blue] [thumbsup2] Do have a look at one of the links at the bottom of my post. The links will help you [blue]ask better questions[/blue], get [blue]quick responses[/blue], [blue]better answers[/blue], and insite into [blue]etiquette[/blue] here in the forums. Again . . . Welcome to [blue]Tek-Tips![/blue] [thumbsup2] [blue]Its Worthy Reading![/blue]

See Ya! . . . . . .

Be sure to see thread181-473997 [blue]Worthy Reading![/blue] [thumbsup2]
Also faq181-2886 [blue]Worthy Reading![/blue] [thumbsup2]
 
But if BeforeUpdate isn't being used, what would make this code do anything?

Form_BeforeUpdate always fires when a record is saved, and DoCmd.Save does not save a record! It saves Design Changes made to an object, such as a form.

To force a record save use

If Me.Dirty Then Me.Dirty = False.

or

DoCmd.RunCommand acCmdSaveRecord

The Missinglinq

Richmond, Virginia

There's ALWAYS more than one way to skin a cat!
 
Status
Not open for further replies.

Part and Inventory Search

Sponsor

Back
Top