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

Always Prompt to Save New or Edited Record 1

Status
Not open for further replies.

capndave

Technical User
Mar 4, 2003
36
US
I have a form that opens via a choice of several command buttons; one opens to edit existing records the other opens in data entry for new records. There are several required fields, but not all need to be required. I want the user to be prompted to Save new record YES or NO in the data entry form regardless of how many fields are complete and I want the user to be prompted to save changes Yes or No when the form opens in the edit mode. These prompts need to occur when the user attempts to close either form via a command button on each form.

thanks
 
Try this in the code editor behind the appropriate forms.
The code will work for either AddMode or EditMode form, and will differentiate between the two with an appropriate message.
Code:
Private Sub Form_BeforeUpdate(Cancel As Integer)
If Not (Me.NewRecord) Then
 If MsgBox("Would You Like To Save The Changes To This Record?", vbQuestion + vbYesNo + vbDefaultButton1, "Save Changes to Record ???") = vbNo Then
  Me.Undo
 End If
Else
 If MsgBox("Would You Like To Save This Record?", vbQuestion + vbYesNo + vbDefaultButton1, "Save This Record ???") = vbNo Then
  Me.Undo
 End If
End If
End Sub



The Missinglinq

Richmond, Virginia

There's ALWAYS more than one way to skin a cat!
 
Howdy missinglinq . . .
capndave said:
[blue]These prompts need to occur when the user attempts to close either form [purple]via a command button[/purple] on each form[/blue]
I was going to post the same, but the command button changed everything. The button allows the user to navigate to another record before actually hitting the button, and I'm sure you know what to expect.

If we remove the button your code works great, however I don't believe capndave intends to close the form for the 1st new or edited record . . .

Just thinking out loud ;-)

Calvin.gif
See Ya! . . . . . .

Be sure to see thread181-473997
 
Status
Not open for further replies.

Part and Inventory Search

Sponsor

Back
Top