B
Barry
I need to automatically assign a sequential number based on the last four
positions of a text field on a form based on the maximum value of part of the
field +1 and based on the matching the value of the same field to that of a
record in another table.
In Table Service-Contracts I have a text field titled ARL TRACKING NO.
Sample values are as follows:
ARL-2009-0001
ARL-2009-0002
ARL-2009-0003
ARL-2010-0001
ARL-2010-0002
ARL-2010-0003
ARL-2010-0004
In Table FISCAL-YEAR I have a field called FY and there is one record which
equals “2009â€.
In the sample above, I expect to see ARL-2009-0004 displayed on the form,
but see ARL-2010-0000.
VBA Code is below.
I am relatively new to VBA so any assistance will be greatly appreciated.
Private Sub Form_Load()
Me!Combo125.SetFocus
Me!Combo125.SelLength = 0
DoCmd.GoToRecord , , acNewRec
If Me.NewRecord Then
Dim varResult As Variant
varResult = DMax("[ARL TRACKING NO]", "[SERVICE-CONTRACTS]", "[ARL
TRACKING NO]" Like "[FISCAL-YEAR].[FY]")
If IsNull(varResult) Then 'just in case the table is empty
Me.[ARL TRACKING NO] = "ARL-2010-0000"
Else
Me.[ARL TRACKING NO] = Left(varResult, 10) & Val(Right(varResult, 3))
+ 1
End If
Else
MsgBox "No new record created!"
End If
End Sub
positions of a text field on a form based on the maximum value of part of the
field +1 and based on the matching the value of the same field to that of a
record in another table.
In Table Service-Contracts I have a text field titled ARL TRACKING NO.
Sample values are as follows:
ARL-2009-0001
ARL-2009-0002
ARL-2009-0003
ARL-2010-0001
ARL-2010-0002
ARL-2010-0003
ARL-2010-0004
In Table FISCAL-YEAR I have a field called FY and there is one record which
equals “2009â€.
In the sample above, I expect to see ARL-2009-0004 displayed on the form,
but see ARL-2010-0000.
VBA Code is below.
I am relatively new to VBA so any assistance will be greatly appreciated.
Private Sub Form_Load()
Me!Combo125.SetFocus
Me!Combo125.SelLength = 0
DoCmd.GoToRecord , , acNewRec
If Me.NewRecord Then
Dim varResult As Variant
varResult = DMax("[ARL TRACKING NO]", "[SERVICE-CONTRACTS]", "[ARL
TRACKING NO]" Like "[FISCAL-YEAR].[FY]")
If IsNull(varResult) Then 'just in case the table is empty
Me.[ARL TRACKING NO] = "ARL-2010-0000"
Else
Me.[ARL TRACKING NO] = Left(varResult, 10) & Val(Right(varResult, 3))
+ 1
End If
Else
MsgBox "No new record created!"
End If
End Sub