Hi, can anybody help I am trying to set a minimum value when scanning a barcode in to a textbox to a minimum of 47 digits so if a barcode is scanned with less than 47 digits it will error but I can not get it to work. below is the vba I am using now which works fine for scanning but it excepts barcodes with less than 47 digits I have tried using if len(textbox2.value) <> 47 with now joy.
Private Sub textbox2_Change()
Dim erow As Long
If Len(TextBox2.Value) = 47 Then
Application.DisplayAlerts = False
erow = ActiveSheet.Cells(Rows.Count, 1).End(xlUp).Offset(1, 0).Row
Cells(erow, 1) = TextBox1.Text
Cells(erow, 2) = TextBox2.Text
Cells(erow, 7) = TextBox3.Text
Cells(erow, 6) = TextBox4.Text
Range("H" & Rows.Count).End(xlUp).Offset(1).Value = Now
Cells(erow, 3).FormulaR1C1 = "=mid(rc[-1],4,4)"
Cells(erow, 4).FormulaR1C1 = "=mid(rc[-2],8,4)"
Cells(erow, 5).FormulaR1C1 = "=mid(rc[-3],30,6)"
Range("A1").End(xlDown).Select
TextBox2.Text = ""
TextBox3.Text = ""
TextBox2.Visible = True
TextBox4.Text = ""
TextBox1.Visible = True
TextBox3.Visible = False
TextBox4.Visible = False
Label3.Visible = False
Label4.Visible = False
Label5.Visible = False
Label6.Visible = False
Application.DisplayAlerts = True
TextBox2.SetFocus
End If
End Sub
Regards
Private Sub textbox2_Change()
Dim erow As Long
If Len(TextBox2.Value) = 47 Then
Application.DisplayAlerts = False
erow = ActiveSheet.Cells(Rows.Count, 1).End(xlUp).Offset(1, 0).Row
Cells(erow, 1) = TextBox1.Text
Cells(erow, 2) = TextBox2.Text
Cells(erow, 7) = TextBox3.Text
Cells(erow, 6) = TextBox4.Text
Range("H" & Rows.Count).End(xlUp).Offset(1).Value = Now
Cells(erow, 3).FormulaR1C1 = "=mid(rc[-1],4,4)"
Cells(erow, 4).FormulaR1C1 = "=mid(rc[-2],8,4)"
Cells(erow, 5).FormulaR1C1 = "=mid(rc[-3],30,6)"
Range("A1").End(xlDown).Select
TextBox2.Text = ""
TextBox3.Text = ""
TextBox2.Visible = True
TextBox4.Text = ""
TextBox1.Visible = True
TextBox3.Visible = False
TextBox4.Visible = False
Label3.Visible = False
Label4.Visible = False
Label5.Visible = False
Label6.Visible = False
Application.DisplayAlerts = True
TextBox2.SetFocus
End If
End Sub
Regards