Previous Command No Longer Works

  • Thread starter pushrodengine via AccessMonster.com
  • Start date
P

pushrodengine via AccessMonster.com

I’m using coding below to insert “0000-yy†into a textbox.
The numbering system works great except that I have lost the ability to move
back to the previous record. It must be something to do with the code.

How can I fix it?


Private Sub Form_Current()
If Me.NewRecord Then
Dim strWhere As String
Dim varResult As Variant

strWhere = "IncidentID Like """ & Format(Date, "yy") & "*"""
varResult = DMax("IncidentID", "tblIncidentLog", strWhere)

If IsNull(varResult) Then
Me.IncidentID = Format(Date, "yy") & "-0001"
Else
Me.IncidentID = Left(varResult, 3) & _
Format(Val(right(varResult, 4)) + 1, "0000")
End If
End If
End Sub
 
A

Allen Browne

You *never* want to assign a value to a bound control in Form_Current. It
makes no sense to alter the data in the record just because somebody visited
it. That would imply that the data would be invalid if nobody visited the
record.

In your case, you don't want to dirty the record until you know the user
intends entering something. Ideally, you want to run this at the last
possible moment before the new record is saved, to reduce the possibility
that 2 users entering data together are given the same number. Move the code
into Form_BeforeUpdate().
 

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