PDA

View Full Version : Need help with VBA Comfirmation box if user edits records



keek2a4
03-12-2008, 04:50 AM
Hi, need some guidance here....

I am using microsoft access and I need to implement the following feature in VBA. I have a form called "frmStudentDetails" that displays a single record of a student from the table "tblStudent". The fields that are displayed are studentName, studentSchool, studentAge and dateLastupdated.

If a user edits or changes any fields in the form, then I need a comfirmation box to pop up with a yes/no option? If the user presses Yes then the new edit record is saved and the "dateLastUpdated" field is updated to the current date. If the user presses No then there is new edited record is undo to the original record and there is no update to the "DateLastUpdated"

What is the best way to implement this? I have attached a my sample database with this post.

Thanks

DarkSprout
03-12-2008, 05:23 AM
This maybe what your looking for:

Private Sub Command4_Click() ' Close Form
Const DBLINE = vbCrLf & vbCrLf
If [Dirty] Then
If MsgBox("Record#" & [ID] & " has changed " & DBLINE _
& "Do You which to save the Edited Changes", 292, "Record Change") = vbNo Then [Undo]
End If
DoCmd.Close acForm, Me.Name
End Sub

orange
03-12-2008, 05:27 AM
Hi, need some guidance here....

I am using microsoft access and I need to implement the following feature in VBA. I have a form called "frmStudentDetails" that displays a single record of a student from the table "tblStudent". The fields that are displayed are studentName, studentSchool, studentAge and dateLastupdated.

If a user edits or changes any fields in the form, then I need a comfirmation box to pop up with a yes/no option? If the user presses Yes then the new edit record is saved and the "dateLastUpdated" field is updated to the current date. If the user presses No then there is new edited record is undo to the original record and there is no update to the "DateLastUpdated"

What is the best way to implement this? I have attached a my sample database with this post.

Thanks

In the code behind the form, I'd use the Me.Dirty property to identify if something on the form has been changed.
Ask if user wishes to Save the change, then save it with current date. If user wishes not to Save, then just exit --- without saving the record.

keek2a4
03-12-2008, 06:23 AM
Thanks for your replies, yes it does work. Orange do u mean using me.Dirty in the if statement. Also if vbNo then (Undo), however how do I update the current date if vbYes is true?

DarkSprout
03-12-2008, 06:46 AM
Refer to my post, I will just save it, if no [Undo] is used.

=DarkSprout=

orange
03-12-2008, 08:07 AM
Thanks for your replies, yes it does work. Orange do u mean using me.Dirty in the if statement. Also if vbNo then (Undo), however how do I update the current date if vbYes is true?
Yes, as DarkSprout has shown, use the me.Dirty in the If statement.

To update the current date

Whatever you're using as the recordsource for the Form, when referring to the field in the recordset -
let's say its rs!LastUpdateDate, you will have to assign a value such as
rs!LastUpdatedate = Date, then

DoCmd.RunCommand acCmdSaveRecord


Hope this is helpful.

keek2a4
03-12-2008, 09:42 AM
Hi, Thanks for your reply, it works perfectly. Thanks really appreciate it