7,762
社区成员
发帖
与我相关
我的任务
分享
Private Declare Function GetTickCount Lib "kernel32" () As Long '调用api实现延迟200ms
Dim rs As ADODB.Recordset
Private Function Delay(MSceond As Long)
Dim i As Long
If MSceond < 2 Then Exit Function
i = GetTickCount
Do While GetTickCount - i < MSceond
DoEvents
Loop
End Function
Private Sub cmdquit_Click()
Unload Me
End Sub
Private Sub Form_Load()
Me.Top = 5610 - Me.Height / 2
Me.Left = 7740 - Me.Width / 2
Set rs = New ADODB.Recordset
rs.ActiveConnection = cnn
rs.CursorType = adOpenDynamic
rs.LockType = adLockOptimistic
rs.Source = "select 条码,日期 from 条码"
rs.Open
End Sub
Private Sub txtbarcode_KeyPress(KeyAscii As Integer)
If KeyAscii = vbKeyReturn Then
Dim rs2 As ADODB.Recordset
Set rs2 = New ADODB.Recordset
rs2.CursorType = adOpenStatic
rs2.Source = "select 条码,日期 from 条码 where 条码='" & Trim(txtbarcode.Text) & "'"
rs2.ActiveConnection = cnn
rs2.Open
Debug.Print rs2.RecordCount
If rs2.RecordCount = 0 Then
rs.Requery
If Len(txtbarcode.Text) > 8 Then
With rs
.AddNew
.Fields(0).Value = Trim(txtbarcode.Text)
.Fields(1).Value = Date
.Update
End With
Frame1.Caption = "正在输入条码......"
Delay (1000)
Frame1.Caption = "条码扫描"
txtbarcode.Text = ""
Else
MsgBox "错误的条码,不能输入!"
End If
Else
MsgBox "该条码已于" & rs2.Fields(1).Value & "日导入,请确认!"
End If
End If
Exit Sub
End Sub