Part of the Procedure not to execute in eddit mode

  • Thread starter injanib via AccessMonster.com
  • Start date
I

injanib via AccessMonster.com

Some one please look at the code below and tell me how I can modify it so
that the portion of the code containing:

Me![txtItemNumber] = Format(DMax("[ItemNumber]", "[Tracking]") + 1, "000000")
[TimeReceived] = Date
[Time] = Now()

NOT execute if the form is opened in edit mode. Because if I have to modify
the content of the txtFedExTest field I don't want the initial time and date
change and also the txtItemNumber field which is the record ID should also
stay the same.

Private Sub txtFedExTest_AfterUpdate()
If IsNull(Me.txtFedExTest) Or Me.txtFedExTest = "" Then
MsgBox "You must enter a tracking number.", vbOKOnly, "Data Required!"
Else
If Len([txtFedExTest]) = 32 Then
[TrackingNumber] = Mid([txtFedExTest], 17, 12)
Else
[TrackingNumber] = Me.txtFedExTest
End If
Me![txtItemNumber] = Format(DMax("[ItemNumber]", "[Tracking]") + 1,
"000000")
[TimeReceived] = Date
[Time] = Now()

End If
End Sub

Thanks allot
 
G

George Nicholson

NOT execute if the form is opened in edit mode
Define 'edit mode'.

If that means that you *only* want the code to execute when there's a New
record involved:

If Me.NewRecord Then
Me![txtItemNumber] = Format(DMax("[ItemNumber]", "[Tracking]") + 1,
"000000")
[TimeReceived] = Date
[Time] = Now()
End If

If txtFedExTest can get "filled in" for the 1st time after the record has
been initially saved, you should be able to use the OldValue property:
If Len(nz(txtFedExTest.OldValue,"")) = 0 AND
Len(nz(txtFedExTest.Value,"")) >0 Then
' control just filled in for 1st time in an existing record
'.... your code here
End If

OldValue & Value will be different once there is a change to a bound control
and until that record is saved or undone.

HTH,
 

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