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

Save Prompt that comes up when a Command Button is Pressed on a Form

Status
Not open for further replies.

MattMeat

Programmer
Nov 6, 2001
38
0
0
US
Hello Everyone,

I was wondering how I could get a Save Prompt ("Yes" or "No") to come up on a form when a command button ("Close") is pressed. The button is already attached to a Macro that brings a prompt up if there is a change in the design view of the form. But I need the prompt to come up if any of the data has been updated on the form.

Also, as of now, when the button is pressed, the form just closes and saves. This is another reason for the prompt I want to put on the form. I need to give the option of not saving any of the changes.

Hope I have been clear enough
Thanks,
Matt
 
In the CloseObject line of your Macro, It asks whether you want to Save. The Options are Yes, No, and Prompt. You want Prompt. Sean.
 
Sean,

Yeah. I tried that but no prompt comes up. The only time I see a prompt is when a change has been made in design view. Otherwise, the button closes and saves the form, even if "Prompt" is set in the macro's closeobject line. Do you know another way?

Matt
 
Hi,

The "Prompt" is only set for the object (in this case the form).

My guess is you form is bound to a table/query so try this:


Dim UserResp As String
If Me.Dirty = True Then
UserResp = MsgBox("Save Form", vbYesNoCancel + vbQuestion, "Save Check")
If UserResp = vbYes Then
DoCmd.Save
DoCmd.Close
ElseIf UserResp = vbNo Then
Me.Undo
DoCmd.Close
Else
DoCmd.CancelEvent
End If
Else
DoCmd.Close
End If

If this doesn't work, let me know

Kyle ::)
 
Status
Not open for further replies.

Part and Inventory Search

Sponsor

Back
Top