Hello there,
The vba code is working just fine if i enter a number ( id code of a product ) smaller than 10 digits.
Now if i type a number ( id code of a product ) bigger than 10 digits, example 7908147464200, i get a vba error 6 overflow.
Is it because of the CLng? And if it is, how can i fix it? Thanks.
The vba code is working just fine if i enter a number ( id code of a product ) smaller than 10 digits.
Now if i type a number ( id code of a product ) bigger than 10 digits, example 7908147464200, i get a vba error 6 overflow.
Is it because of the CLng? And if it is, how can i fix it? Thanks.
VBA Code:
Private Sub Reg1_AfterUpdate()
'Check to see if value exists
If WorksheetFunction.CountIf(Sheet2.Range("B:B"), Me.reg1.Value) = 0 Then
MsgBox "This is an incorrect ID"
Me.reg1.Value = ""
Exit Sub
End If
'Lookup values based on first control
With Me
.reg2 = Application.WorksheetFunction.VLookup(CLng(Me.reg1), Sheet2.Range("Lookup"), 2, 0)
.reg3 = Application.WorksheetFunction.VLookup(CLng(Me.reg1), Sheet2.Range("Lookup"), 3, 0)
.reg4 = Application.WorksheetFunction.VLookup(CLng(Me.reg1), Sheet2.Range("Lookup"), 4, 0)
.reg5 = Application.WorksheetFunction.VLookup(CLng(Me.reg1), Sheet2.Range("Lookup"), 5, 0)
.reg6 = Application.WorksheetFunction.VLookup(CLng(Me.reg1), Sheet2.Range("Lookup"), 6, 0)
.reg7 = Application.WorksheetFunction.VLookup(CLng(Me.reg1), Sheet2.Range("Lookup"), 7, 0)
End With
End Sub