On Dirty issue?

Z

Zaz

I've been dealing with an issue for quite some time now that I can't resolve.
I have a form that calculates 'Quantity On Hand' based on 'Quantity
Dispersed' and 'Original Quantity'. I also have a function that asks the
user if they want to save changes before an update. In order to get the
'Quantity On Hand' to update properly, I perform a Me.Refresh when the field
loses focus. At this point, the message box pops up asking if the user wants
to save changes. If you then proceed to the next record or close the form
without making any other changes, the message box pops up again. Here is the
relevant code, please advise how I may resolve this issue...

Private Sub Form_BeforeUpdate(Cancel As Integer)
[TxtInitials] = CurrentUser()
[TxtLastUpdated] = Now()

On Error GoTo ErrHandler

Dim answer As Integer

If (Me.Dirty) Then
answer = MsgBox("The record has been modified." & vbCrLf & _
"Do you wish to save changes?", vbYesNo, "Save Changes?")

If (answer = vbNo) Then
Me.Undo
End If
End If

Exit Sub

ErrHandler:

MsgBox "Error in Form_BeforeUpdate( ) in" & vbCrLf & Me.Name & _
" form." & vbCrLf & vbCrLf & _
"Error #" & Err.Number & vbCrLf & Err.Description
Err.Clear

End Sub


Private Sub TxtQtyDispersed_LostFocus()
Me.Refresh
Me.TxtQtyOnHand = TxtOriginalQty - DSum("[QtyDispersed]", "API_SUBLOT",
"[TxtLotNumber]=[LotNumber]")
End Sub
 

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