试一下
Dim Conn As New ADODB.Connection,RsMain As New ADODB.Recordset,MainSQL As String
1. 使用回车响应
Private Sub Text1_KeyPress(KeyAscii As Integer)
If KeyAscii = 13 then
MainSQL = "Select * from [Sheet1$] in 'C:\SN.xls' 'Excel 8.0;' where [SN] = '" & Trim(Text1.text) & "'" ----> 'C:\SN.xls' 为Excel路径,首行插入一行表头"SN"
RsMain.open MainSQL ,Conn,1,1
If Not RsMain.EOF then
Label1.Caption = "合法条码"
ELSE
Label1.Caption = "非法条码"
Endif
RsMain.close
Text1.Setfocus
EndIf
2. 数据输入后自动响应 (利用文本框数据变化时字长判断)
Private Sub Text1_Change()
If Len(Trim(Text1.Text)) = 18 Then
MainSQL = "Select * from [Sheet1$] in 'C:\SN.xls' 'Excel 8.0;' where [SN] = '" & Trim(Text1.Text) & "'"
RsMain.Open MainSQL, Conn, 1, 1
If Not RsMain.EOF Then
Label1.Caption = "合法条码"
Else
Label1.Caption = "非法条码"
End If
RsMain.Close
Else
Label1.Caption = "非法条码"
End If
Text1.SetFocus
[ 本帖最后由 owenlu1981 于 2014-3-7 10:24 编辑 ]
Dim Conn As New ADODB.Connection,RsMain As New ADODB.Recordset,MainSQL As String
1. 使用回车响应
Private Sub Text1_KeyPress(KeyAscii As Integer)
If KeyAscii = 13 then
MainSQL = "Select * from [Sheet1$] in 'C:\SN.xls' 'Excel 8.0;' where [SN] = '" & Trim(Text1.text) & "'" ----> 'C:\SN.xls' 为Excel路径,首行插入一行表头"SN"
RsMain.open MainSQL ,Conn,1,1
If Not RsMain.EOF then
Label1.Caption = "合法条码"
ELSE
Label1.Caption = "非法条码"
Endif
RsMain.close
Text1.Setfocus
EndIf
2. 数据输入后自动响应 (利用文本框数据变化时字长判断)
Private Sub Text1_Change()
If Len(Trim(Text1.Text)) = 18 Then
MainSQL = "Select * from [Sheet1$] in 'C:\SN.xls' 'Excel 8.0;' where [SN] = '" & Trim(Text1.Text) & "'"
RsMain.Open MainSQL, Conn, 1, 1
If Not RsMain.EOF Then
Label1.Caption = "合法条码"
Else
Label1.Caption = "非法条码"
End If
RsMain.Close
Else
Label1.Caption = "非法条码"
End If
Text1.SetFocus
[ 本帖最后由 owenlu1981 于 2014-3-7 10:24 编辑 ]