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

Validate that data has been edited

Status
Not open for further replies.

herrld

Technical User
May 10, 2001
69
US
I have a form that is based on a query which contains 2 tables. These tables have a one-to-one relationship.
This form allows edits and deletions.
I have a SAVE button on my form. The code follows.

Private Sub SaveBtn_Click()
On Error GoTo Err_SaveBtn_Click

DoCmd.DoMenuItem acFormBar, acRecordsMenu, acSaveRecord, , acMenuVer70
MsgBox "Your Data is Saved!", vbOKOnly

Exit_SaveBtn_Click:
Exit Sub

Err_SaveBtn_Click:
MsgBox Err.Description
Resume Exit_SaveBtn_Click

End Sub

This works fine except I would like to verify that the user did actually change data in one of the fields prior to returning the message 'Your Data is Saved!'

Currently, after clicking on the SaveBtn, the record is saved and the user receives the message.
I would like it to say something like 'You have not made any changes to the data' if in fact no edit has been made.

Does this make sense at all?

Linda
 
How many fields are on the form?

If there isn't too many fields then set a variable and add code to the after update of every field.

example

Dim intRecEdit as integer

intRecEdit = 0

Private Sub MyField_AfterUpdate()

intRecEdit = 1

End Sub

Private Sub SaveBtn_Click()
On Error GoTo Err_SaveBtn_Click

If intRecEdit = 1 Then
DoCmd.DoMenuItem acFormBar, acRecordsMenu, acSaveRecord, , acMenuVer70
MsgBox "Your Data is Saved!", vbOKOnly
Else
MsgBox "You have not made any changes to the data.",vbOkOnly
End if


Exit_SaveBtn_Click:
Exit Sub

Err_SaveBtn_Click:
MsgBox Err.Description
Resume Exit_SaveBtn_Click

End Sub


 
I have 25 fields on the form that can be edited.
Does that seem like too many?

Linda
 
You can use the forms Dirty property to determine whether any changes have been made to the form since last save. Something like:

Private Sub SaveBtn_Click()
On Error GoTo Err_SaveBtn_Click

If Me.Dirty Then
DoCmd.DoMenuItem acFormBar, acRecordsMenu, acSaveRecord, , acMenuVer70
MsgBox "Your Data is Saved!", vbOKOnly
Else
'No changes were made
MsgBox "No changes were made to the record."
End If

Exit_SaveBtn_Click:
Exit Sub

Err_SaveBtn_Click:
MsgBox Err.Description
Resume Exit_SaveBtn_Click

End Sub

Hope that helps

-Gary
 
Thanks Gary.

That worked. Very cool!

Linda
 
If you need to confirm that specific fields have been changed rather than that just one has changed (triggering dirty status), you could

1) In the Current event (meaning a record has just been loaded/selected) store the values.
2) At save time see if all the correct values have changed.

The problem with all of these is if the user can leave the current record by any method without pressing Save.
 
Status
Not open for further replies.

Part and Inventory Search

Sponsor

Back
Top