PDA

View Full Version : Save Prompt....



parttime_guy
04-21-2011, 09:07 PM
Hi Guz & Galz,

I have created a Database form which has more than 25 fields (some of which are combo boxes), there are about 1000+ rows.

On selection of a particular client (via Combo box) all records are filled in the respective fields (it reads the row information).

Some of the Combo boxes are Distinct.

Currently, if the user selects anything in the Combo box/fields it get updated/saves the information in the master table.

Query
I don't want a save button on the Form - Is it possible to create a prompt which has a save/cancel/undo button - the prompt checks for any changes done on the form that would include any field and Combo boxes - the prompt would occur only after the user select another client - the prompt would not occur if no changes are done.

Just a thought....:think: hope I am not asking for too much - any other ideas welcome.

Best Regards

HiTechCoach
04-29-2011, 08:32 PM
Sure. Use the form's Before Update event.

Example:



Private Sub Form_BeforeUpdate(Cancel As Integer)


' perform data validation
If IsNull(Me.CompanyName) Then

MsgBox "You must enter a Company Name.", vbCritical, "Data entry error..."
DoCmd.GoToControl "CompanyName"

Cancel = True


End If


If Not Cancel Then
' passed the validation process

If Me.NewRecord Then
If MsgBox("Data will be saved, Are you Sure?", vbYesNo, "Confirm") = vbNo Then
Cancel = True
Else
' run code for new record before saving

End If


Else
If MsgBox("Data will be modified, Are you Sure?", vbYesNo, "Confirm") = vbNo Then
Cancel = True
Else
' run code before an existing record is saved
' example: update date last modified

End If
End If

End If


' if the save has been canceled or did not pass the validation , then ask to Undo changes
If Cancel Then

If MsgBox("Do you want to undo all changes?", vbYesNo, "Confirm") = vbYes Then
Me.Undo

End If

End If



End Sub

parttime_guy
05-04-2011, 07:54 AM
Hey Coach,

Sorry for the delay was out-of-town for a few days, Iam surely going to try and use the code on the Database.

Thanks for your help.... :friends: n Best Regards

HiTechCoach
05-04-2011, 08:57 AM
No Problem. Still here.

Hope it helps.

Looking forward to hearing your progress.