【VBA】スキャン文字列の判定

Private Sub CommandButton1_Click()

	UserForm2.Show

End Sub

---------------------------------------------------------


Private Sub Checkbox1_enter()

With TextBox1
           .SetFocus
           .SelStart = 0
           .SelLength = Len(TextBox1)
End With

  

End Sub


Private Sub TextBox1_ Exit(ByVal Cancel As MSForms.ReturnBoolean)


  'スキャン文字列の空白スペースを削除する
  TextBox1.Value = Replace(TextBox1.Value, " ", "")
  TextBox1.Value = Replace(TextBox1.Value, " ", "")

  Checkbox1.Value = False
   Label1.Value = “”
      
  'スキャン文字列の全角文字確認
  If Len(TextBox1.Value) <> LenB(StrConv(TextBox1.Value, vbFromUnicode)) Then

      MsgBox "全角が含まれています"
      TextBox1.Value = ""
      TextBox1.SetFocus

  Else


      'スキャン文字列の桁数確認(16桁以外の文字列は消す)
      If TextBox1.TextLength > 0 And TextBox1.TextLength < 16 Then
  
          MsgBox "桁数が足りません"
          TextBox1.Value = ""
          TextBox1.SetFocus
  
      ElseIf TextBox1.TextLength < 1 Then
  
          TextBox1.SetFocus
  
      Else
  
          '特定履歴へのデータ書き込み
          Select Case Mid(TextBox1.Value, 3, 6)
          
              '得意先コードの判定
              Case "000143"
              
                  MsgBox (Mid(TextBox1.Value, 3, 6))
                  Checkbox1.Value = True
                  Label1.Value = “履歴入力OKCase Else
          
                  MsgBox "パナソニック/YKKではありません"
                  TextBox1.Value = ""
                  TextBox1.SetFocus
          
          End Select

  
      End If
  
  
  End If
  

End Sub

この記事が気に入ったらサポートをしてみませんか?