Hi All;
I have a text field having data i-e HO-1, HO,2, ACW-25 and so on. The field name is nBadge_num and is Unique. The data in this field is sorted automatically like 1, 10, 11, 12, 13, 2, 3, 4, 5...because this is the text field.
The number on the form is automatically generated, when the user type HO- for example on field exit event. The last number will generate like HO-5.
Code for automatic number generation is:
Set rst = dbs.OpenRecordset("SELECT Max(CLng(Right([NBadge_Num],Len([NBadge_Num])-" & Len(Me.NBadge_Num) & ") ) ) AS MaxNo " _
& "FROM newMain " _
& "HAVING InStr(1,[NBadge_Num] ,'" & Me.NBadge_Num & "')=1")
If Not IsNull(rst![Maxno]) Then
Me.NBadge_Num = Me.NBadge_Num & rst![Maxno] + 1
Else
Me.NBadge_Num = Me.NBadge_Num & "1001"
End If
My problem is that code is giving runtime error 3464 Data type mismatch in criteria.
I am trying to resolve but unable :banghead:
Thanking you all in advance
Muaz
I have a text field having data i-e HO-1, HO,2, ACW-25 and so on. The field name is nBadge_num and is Unique. The data in this field is sorted automatically like 1, 10, 11, 12, 13, 2, 3, 4, 5...because this is the text field.
The number on the form is automatically generated, when the user type HO- for example on field exit event. The last number will generate like HO-5.
Code for automatic number generation is:
Set rst = dbs.OpenRecordset("SELECT Max(CLng(Right([NBadge_Num],Len([NBadge_Num])-" & Len(Me.NBadge_Num) & ") ) ) AS MaxNo " _
& "FROM newMain " _
& "HAVING InStr(1,[NBadge_Num] ,'" & Me.NBadge_Num & "')=1")
If Not IsNull(rst![Maxno]) Then
Me.NBadge_Num = Me.NBadge_Num & rst![Maxno] + 1
Else
Me.NBadge_Num = Me.NBadge_Num & "1001"
End If
My problem is that code is giving runtime error 3464 Data type mismatch in criteria.
I am trying to resolve but unable :banghead:
Thanking you all in advance
Muaz