M
Mekinnik via AccessMonster.com
I have this code I got to lookupfrom the MSDS field the highest number
already used for a left 2 letter prefix, then its suppose to add 1 to the
prefix only it doesn't work. The MSDS field prefix is based on the users
selection from another field. Can someone explain why??
Private Sub Form_BeforeUpdate(Cancel As Integer)
Dim varResult As Variant
Dim strWhere As String
Dim iNum As Integer
Dim strFirstChar As String
Dim strVal As String
Me.Dept.SetFocus
strVal = Me.Dept.SelText
strFirstChar = Left(strVal, 2)
strVal = strFirstChar
If Me.NewRecord Then
'Lookup the highest number already used for the prefix.
strWhere = "MSDS Like " "" & Me.[Dept] & " * """"
varResult = DMax("MSDS", "Hazinventory", strWhere)
If Not IsNull(varResult) Then
iNum = Val(Right(varResult, 2)) + 1
End If
'Assign the Value
Me.MSDS = strVal & Format(iNum, "00")
End If
End Sub
already used for a left 2 letter prefix, then its suppose to add 1 to the
prefix only it doesn't work. The MSDS field prefix is based on the users
selection from another field. Can someone explain why??
Private Sub Form_BeforeUpdate(Cancel As Integer)
Dim varResult As Variant
Dim strWhere As String
Dim iNum As Integer
Dim strFirstChar As String
Dim strVal As String
Me.Dept.SetFocus
strVal = Me.Dept.SelText
strFirstChar = Left(strVal, 2)
strVal = strFirstChar
If Me.NewRecord Then
'Lookup the highest number already used for the prefix.
strWhere = "MSDS Like " "" & Me.[Dept] & " * """"
varResult = DMax("MSDS", "Hazinventory", strWhere)
If Not IsNull(varResult) Then
iNum = Val(Right(varResult, 2)) + 1
End If
'Assign the Value
Me.MSDS = strVal & Format(iNum, "00")
End If
End Sub