Help with code please

G

Greg B

I am having trouble with a piece of code, the code works with smaller
numbers but when I scan a barcode it does not recognise the number? What
have I got wrong here is the code below.
Private Sub UserForm_Activate()

TextBox1.Value = InputBox("PLEASE SCAN THE ITEM")


End Sub

Private Sub TextBox1_Change()

Dim CHECK1
Sheet5.Activate
On Error Resume Next
CHECK1 = Application.Match(CLng(TextBox1.Value), Range("A:A"), 0)
If Not IsError(CHECK1) Then
Label1.Caption = Application.Index(Range("B:B"), CHECK1)
End If
On Error GoTo 0

End Sub
 
T

Tom Ogilvy

What is a typical barcode number that is causing problems. What error
message are you getting?
 
G

Greg B

this is the example barcode scanned 9310072020280 the code works with
smaller numbers it does not seem to recognise the 9310072020280

There is no error code as such just the caption does not change with the
larger number.
 
T

Tom Ogilvy

Gregg,
From Help on the LONG data type:

Long (long integer) variables are stored as signed 32-bit (4-byte) numbers
ranging in value from -2,147,483,648 to 2,147,483,647. The type-declaration
character for Long is the ampersand (&).


9,310,072,020,280

is outside this range. Try converting the number to a double (cdbl) since
numbers in the excel sheet are stored as double anyway.

Demo'd from the immediate window:

? cdbl("9310072020280")
9310072020280

--
Regards,
Tom Ogilvy
 
R

Rick Rothstein \(MVP - VB\)

Just to follow up on Tom's reply to you...

The reason you don't see anything is because the number is outside the range
of a Long, your assignment is generating an error, but your On Error Resume
Next statement is hiding that from you. Comment out that statement and you
should be able to see the error.

Rick
 

Ask a Question

Want to reply to this thread or ask your own question?

You'll need to choose a username for the site, which only take a couple of moments. After that, you can post your question and our members will help you out.

Ask a Question

Similar Threads

Advice Please? 3
Barcode Scanner 1
Help with code please? 2
Help on following code please? 2
commandbutton does not answer 0
Copy filtered data to sheet 2 1
Help with code please? 6
Help with code please 1

Top