Ark68
Well-known Member
- Joined
- Mar 23, 2004
- Messages
- 4,566
- Office Version
- 365
- 2016
- Platform
- Windows
Rich (BB code):
Private Sub empl_no2_afterupdate()
If Not mbevents Then Exit Sub
'employee number error checking
If Not empl_no2.Value Like "#####" Then
MsgBox "Employee number has to be 5 numbers. a", , "ERROR"
With empl_no2
.Text = "00000"
.SetFocus
.SelStart = 0
.SelLength = Len(.Text)
End With
Exit Sub
ElseIf Len(empl_no2.Value) <> 5 Then
MsgBox "Employee number has to be 5 numbers. b", , "ERROR"
With empl_no2
.Text = "00000"
.SetFocus
.SelStart = 0
.SelLength = Len(.Text)
End With
Exit Sub
ElseIf CLng(empl_no2.Value) < 11110 Or CLng(empl_no2.Value) > 99999 Then
MsgBox "Employee number has to be 5 numbers. c", , "ERROR"
With empl_no2
.Text = "00000"
.SetFocus
.SelStart = 0
.SelLength = Len(.Text)
End With
Exit Sub
End If
'duplicate employee number
If Application.WorksheetFunction.CountIf(CLng(empl_no2.Value), ws_rstr.Columns(1)) > 0 Then
MsgBox "This employee number is already assigned to " & Application.WorksheetFunction.VLookup(ty, ws_rster.Range("A:E"), 5, False)
End If
End Sub
I am receiving a "Type mismatch" with the line in red as it refers to the CLng(empl_no2.value) portion.
empl_no2 is a 5 character (only numbers) text value in a userform textbox (empl_no2). I am trying to use it's value in a match function but am getting an error, perhaps because I'm trying to compare text to the numeric data in column 1 of worksheet ws_rstr. That is why I put the CLng preceeding it. I thought that would work because I had to do the same thing in the line in blue in order to compare the text with the numbers. I don't get that error on that line.
I don't know what the difference is that it would react with an error in one case, but not the other. What is the solution to resolving this problem?
Last edited: