TextBox Match

johnsonk

Board Regular
Joined
Feb 4, 2019
Messages
162
hi,
I am having a few issues with my code below, what I need it to do is when they enter a value in textbox8 (QTY) either 1,2 or 3 the 3 textboxes 10, 21 & 22 will be visible or not which works ok, the problem I am having is the matchtext if they scan the correct codes in texboxes 10, 21 & 22 to match textbox1 (Label Code) then textbox11 should say Pass but I keep getting a Fail but it works when only scanning one label code (see pics below) ant help would be great.

VBA Code:
Private Sub TextBox8_Change()
If TextBox8.Value = 3 Then Exit Sub
If TextBox8.Value = 1 Then
TextBox21.Visible = False
TextBox22.Visible = False
Else: TextBox8.Value = 2
TextBox22.Visible = False
End If
End Sub

VBA Code:
Sub matchtext()
If TextBox1.Value = "" Or TextBox10.Value = "" Then Exit Sub
If TextBox10.Value + TextBox21.Value + TextBox22.Value = (TextBox1) Then
TextBox11 = ("PASS")
TextBox11.BackColor = vbGreen

Label20.Visible = True
Label21.Visible = True
TextBox16.Visible = True
TextBox17.Visible = True
TextBox18.Visible = True
TextBox19.Visible = True
Else
      TextBox11.BackColor = vbRed
    Application.Speech.Speak "FAIL"
TextBox11 = ("FAIL")
Dim sPath As String
result = MsgBox("THIS LABEL CODE DOES NOT MATCH THE PRICE SHEET", vbOKOnly + vbCritical, "WARNING")
If result = vbOK Then
Dim xOutApp As Object
Dim xOutMail As Object
Dim xMailBody As String
Dim wb As Workbook
On Error Resume Next
Set xOutApp = CreateObject("Outlook.Application")
Set xOutMail = xOutApp.CreateItem(0)
xMailBody = "WARNING" & vbNewLine & vbNewLine & _
"There has been a no match scanning error" & vbNewLine & vbNewLine & _
"LINE NUMBER: " & ComboBox4.Value & vbNewLine & _
"PRODUCT CODE: " & ComboBox1.Value & vbNewLine & _
"PRODUCT DESCRIPTION: " & TextBox2.Value & vbNewLine & _
"LABEL CODE ON PRICE SHEET: " & TextBox1.Value & vbNewLine & _
"LABEL CODE SCANNED: " & TextBox10.Value

On Error Resume Next
With xOutMail
'.To = "jo.blogs"
'.CC = ""
.Subject = "Stores label code scanning error"
.Body = xMailBody
.Attacments = ActiveSheet
.Send
End With
On Error GoTo 0
Set xOutMail = Nothing
Set xOutApp = Nothing

TextBox10.Text = ""
TextBox11.Text = ""
    TextBox10.SetFocus
    TextBox11.BackColor = &H80000002

End If
End If
End Sub

1600163666270.png
1600164284314.png
1600164366134.png
 

Some videos you may like

Excel Facts

Format cells as time
Select range and press Ctrl+Shift+2 to format cells as time. (Shift 2 is the @ sign).

Anthony47

Well-known Member
Joined
Mar 29, 2006
Messages
1,853
I guess that, rather than If TextBox10.Value + TextBox21.Value + TextBox22.Value = (TextBox1) Then, you need
VBA Code:
If TextBox10.Value = TextBox1.Value And TextBox21.Value = TextBox1.Value And TextBox22.Value = TextBox1.Value Then

Bye
 

Fluff

MrExcel MVP, Moderator
Joined
Jun 12, 2014
Messages
46,393
Office Version
  1. 365
Platform
  1. Windows
How about
VBA Code:
   Dim Pass As Boolean

   If TextBox1.Value = "" Or TextBox10.Value = "" Then Exit Sub
   Select Case TextBox1
      Case "1"
         Pass = TextBox10.Value <> ""
      Case "2"
         If TextBox10.Value <> "" And TextBox21.Value <> "" Then Pass = True
      Case "3"
         If TextBox10.Value <> "" And TextBox21.Value <> "" And TextBox22.Value <> "" Then Pass = True
   End Select
   If Pass Then
      TextBox11 = ("PASS")
      TextBox11.BackColor = vbGreen
      
      Label20.Visible = True
      Label21.Visible = True
      TextBox16.Visible = True
      TextBox17.Visible = True
      TextBox18.Visible = True
      TextBox19.Visible = True
   Else
 

johnsonk

Board Regular
Joined
Feb 4, 2019
Messages
162
Hi, I still get a fail when all 3 are entered correct and if I only choose 2 OR 1 I get nothing.

1600168985058.png
1600169095629.png
1600169151781.png
 

Fluff

MrExcel MVP, Moderator
Joined
Jun 12, 2014
Messages
46,393
Office Version
  1. 365
Platform
  1. Windows

ADVERTISEMENT

Which of us are you talking to?
 

johnsonk

Board Regular
Joined
Feb 4, 2019
Messages
162
Sorry, Fluff the reply is to you.

Anthony47, yours work for all 3 but not for 1 or 2 scans
 

Fluff

MrExcel MVP, Moderator
Joined
Jun 12, 2014
Messages
46,393
Office Version
  1. 365
Platform
  1. Windows

ADVERTISEMENT

Can you post your code with the suggestion I made?
 

johnsonk

Board Regular
Joined
Feb 4, 2019
Messages
162
VBA Code:
rivate Sub TextBox8_Change()
If TextBox8.Value = 3 Then Exit Sub
If TextBox8.Value = 1 Then
TextBox10.Visible = False
TextBox22.Visible = False
Else: TextBox8.Value = 2
TextBox10.Visible = False
End If
End Sub

VBA Code:
Sub matchtext()
Dim Pass As Boolean
   If TextBox1.Value = "" Or TextBox10.Value = "" Then Exit Sub
Select Case TextBox1
Case "1"
Pass = TextBox10.Value <> ""
Case "2"
If TextBox10.Value <> "" And TextBox21.Value <> "" Then Pass = True
Case "3"
If TextBox10.Value <> "" And TextBox21.Value <> "" And TextBox22.Value <> "" Then Pass = True
End Select
If Pass Then
TextBox11 = ("PASS")
TextBox11.BackColor = vbGreen

Label20.Visible = True
Label21.Visible = True
TextBox16.Visible = True
TextBox17.Visible = True
TextBox18.Visible = True
TextBox19.Visible = True
Else
      TextBox11.BackColor = vbRed
    Application.Speech.Speak "FAIL"
TextBox11 = ("FAIL")
Dim sPath As String
result = MsgBox("THIS LABEL CODE DOES NOT MATCH THE PRICE SHEET", vbOKOnly + vbCritical, "WARNING")
If result = vbOK Then
Dim xOutApp As Object
Dim xOutMail As Object
Dim xMailBody As String
Dim wb As Workbook
On Error Resume Next
Set xOutApp = CreateObject("Outlook.Application")
Set xOutMail = xOutApp.CreateItem(0)
xMailBody = "WARNING" & vbNewLine & vbNewLine & _
"There has been a no match scanning error" & vbNewLine & vbNewLine & _
"LINE NUMBER: " & ComboBox4.Value & vbNewLine & _
"PRODUCT CODE: " & ComboBox1.Value & vbNewLine & _
"PRODUCT DESCRIPTION: " & TextBox2.Value & vbNewLine & _
"LABEL CODE ON PRICE SHEET: " & TextBox1.Value & vbNewLine & _
"LABEL CODE SCANNED: " & TextBox10.Value

On Error Resume Next
With xOutMail
'.To = ""
'.CC = ""
.Subject = "Stores label code scanning error"
.Body = xMailBody
.Attacments = ActiveSheet
.Send
End With
On Error GoTo 0
Set xOutMail = Nothing
Set xOutApp = Nothing

TextBox10.Text = ""
TextBox11.Text = ""
TextBox21.Text = ""
TextBox22.Text = ""
    TextBox21.SetFocus
    TextBox11.BackColor = &H80000002

End If
End If
End Sub
 

Fluff

MrExcel MVP, Moderator
Joined
Jun 12, 2014
Messages
46,393
Office Version
  1. 365
Platform
  1. Windows
How are you calling that code & is it in the userform module?
 

johnsonk

Board Regular
Joined
Feb 4, 2019
Messages
162
I can not find where it is calling it from it is not from a module, would I be able to change the way it is called
 

Watch MrExcel Video

Forum statistics

Threads
1,109,084
Messages
5,526,757
Members
409,718
Latest member
koppahollic

This Week's Hot Topics

Top