有空整理一下!
Private Sub Text1_KeyPress(KeyAscii As Integer)
Dim rs As ADODB.Recordset
Dim sql As String
If KeyAscii = 13 And Trim(Text1.Text) <> "" Then
If Len(Trim(Text1)) <> 15 Then
MsgBox "错误的号码!", vbOKOnly + vbExclamation
Text1.SelStart 0
Text1.SelLength = Len(Text1.Text)
Exit Sub
End If
If cn.State = adStateClosed Then
cn.Open "Provider=Microsoft.Jet.OLEDB.4.0;Data Source=e:\山东波导串号\sdch.mdb;Mode=ReadWrite|Share Deny None;Persist Security Info=False"
end if
sql = "select * from 新串号 where 串号='" & Trim(Text1.Text) & "'"
Set rstemp = cn.Execute(sql)
If Not rstemp.EOF Then
rstemp.Close
MsgBox "重复的号码!", vbOKOnly + vbExclamation
Text1.SelStart 0
Text1.SelLength = Len(Text1.Text)
Exit Sub
End If
sql = "insert into 新串号(型号,地区,箱号,串号,代理商,日期,备注) values('" & Trim(combo1.Text) & "','" & Trim(combo2.Text) & "','" & Trim(text2.Text) & "','" & Trim(Text1.Text) & "','" & Trim(combo3.Text) & "','" & dt1 & "','" & Trim(text3.Text) & "')"
cn.Execute sql
Text1.Text = ""
Text1.SetFocus
End If
End Sub
If Len(Text1) = 15 Then
If cn.State = adStateClosed Then
cn.Open "Provider=Microsoft.Jet.OLEDB.4.0;Data Source=e:\山东波导串号\sdch.mdb;Mode=ReadWrite|Share Deny None;Persist Security Info=False"
End If
If rs.State = adStateOpen Then
Set rs = Nothing
End If
rs.Open "新串号", cn, adCmdTable, adLockPessimistic
If rs.Supports(adAddNew) Then
rs.AddNew
On Error GoTo e1
If Text3 = "" Then Text3 = "无"
rs("型号") = Trim(Combo1)
rs("地区") = Trim(Combo2)
rs("箱号") = Text2
rs("串号") = Text1
rs("代理商") = Trim(Combo3)
rs("日期") = DT1
rs("备注") = Text3
rs.Update
Text1.Text = ""
Exit Sub
End If
e1:
我也老做条码扫描器的程式,可是没遇到过你说的问题。
我一般这么做
Private Sub Text1_KeyPress(KeyAscii As Integer)
If KeyAscii = 13 And Text1.Text <> "" Then
'判断是否重复
If 重复的 Then MsgBox "该号码重复了!", vbOKOnly + vbExclamation
End If
End Sub
#If Win16 Then
Declare Sub SetWindowPos Lib "User" (ByVal hwnd As Integer, ByVal hWndInsertAfter As Integer, ByVal X As Integer, ByVal Y As Integer, ByVal cx As Integer, ByVal cy As Integer, ByVal wFlags As Integer)
#Else
Declare Function SetWindowPos Lib "user32" (ByVal hwnd As Long, ByVal hWndInsertAfter As Long, ByVal X As Long, ByVal Y As Long, ByVal cx As Long, ByVal cy As Long, ByVal wFlags As Long) As Long
#End If