After a textbox ("Name") I need a serial number in my form, so I write the following on the afterUpdate event of name:
*************
Dim sdate As String
Dim sNum As Integer
sdate = Format(Date, "yyyymmdd")
sNum = DMax("mid([dtjm],3,3)", "aa", "Right([dtjm],8)= sdate")
If Nz(DMax("right([dtjm],8)", "aa", ""), 0) <> sdate Then
Me.dtjm = "P-" & "001" & "-" & sdate
Else
Me.dtjm = "P-" & Format(Val(sNum) + 1, "000") & "-" & sdate
End If
**************
However it doesn't work, the problem seems to be from:
sNum = DMax("mid([dtjm],3,3)", "aa", "Right([dtjm],8)= sdate")
but if I change it like:
sNum = DMax("mid([dtjm],3,3)", "aa", "")
the whole code works well.
Could anybody help me?
*************
Dim sdate As String
Dim sNum As Integer
sdate = Format(Date, "yyyymmdd")
sNum = DMax("mid([dtjm],3,3)", "aa", "Right([dtjm],8)= sdate")
If Nz(DMax("right([dtjm],8)", "aa", ""), 0) <> sdate Then
Me.dtjm = "P-" & "001" & "-" & sdate
Else
Me.dtjm = "P-" & Format(Val(sNum) + 1, "000") & "-" & sdate
End If
**************
However it doesn't work, the problem seems to be from:
sNum = DMax("mid([dtjm],3,3)", "aa", "Right([dtjm],8)= sdate")
but if I change it like:
sNum = DMax("mid([dtjm],3,3)", "aa", "")
the whole code works well.
Could anybody help me?