Ensure fields were changed before saving

J

Jadabug

I have a form with a subform. On the subform, there are three
different bound txtboxes that will need to be changed if checkbox
"RevReq"=1. I would like to require these fields be dirty before
prompting a save. My code is listed below, and the problem could very
well be my ignorance of the "dirty" feature. Please advise...

Private Sub CloseRevReview_Click()
On Error GoTo Err_CloseRevReview_Click

If Me.RevReq = 1 Then
If Me.txtMC_Num.Dirty = False Or Me.txtRev_D.Dirty = False Or
Me.txtRev_Num.Dirty = False Then
MsgBox "Please ensure all fields are completed."
Me.txtMC_Num.BackColor = vbYellow
Me.txtRev_D.BackColor = vbYellow
Me.txtRev_Num.BackColor = vbYellow
Me.txtMC_Num.SetFocus
Me.ckClosureComplete.Value = False
End If
Exit Sub
ElseIf Me.ckRevReq = 2 Then
If IsNull(Me.memComments) Then
MsgBox "Please enter reasons no revision is necessary."
Me.memComments.BackColor = vbYellow
Me.memComments.SetFocus
Me.ckClosureComplete.Value = False
End If
Exit Sub
Else
Select Case MsgBox("Would you like to save the closeout of this
review?", _
vbYesNoCancel + vbQuestion, "Save Review?")
Case vbNo 'User does not want to save changes
Me.ckClosureComplete = False
Me.Undo
DoCmd.Close
DoCmd.OpenForm "Start Up"
Case vbCancel 'User Cancelled the action
Case Else 'Must have said "Yes"
'Save it
DoCmd.Close
DoCmd.OpenForm "Start Up"
End Select
End If
Exit_BttnClose_Click:
Exit Sub

DoCmd.Close

Exit_CloseRevReview_Click:
Exit Sub

Err_CloseRevReview_Click:
MsgBox Err.Description
Resume Exit_CloseRevReview_Click

End Sub
 
K

Klatuu

The Dirty property only applies to Form and Report objects. If you need to
see if an individual field has changed value:
If Me.MyControl <> Me.MyControl.OldValue Then
MsgBox Me.MyControl.Name & " Has Changed"
End If

So you could change this:
If Me.txtMC_Num.Dirty = False Or Me.txtRev_D.Dirty = False Or
Me.txtRev_Num.Dirty = False Then

To:
If Me.txtMC_Num <> Me.txtMC_Num.OldVaue Or _
Me.txtRev_D <> Me.txtRev_D.OldValue Or _
Me.txtRev_Num <> Me.txtRev_Num <> Me.txtRev_Num.OldValue Then

The OldValue property will only change when you move to a different record.
 

Ask a Question

Want to reply to this thread or ask your own question?

You'll need to choose a username for the site, which only take a couple of moments. After that, you can post your question and our members will help you out.

Ask a Question

Top