给你点代码Private Sub Grid_KeyUp(KeyCode As Integer, Shift As Integer) Dim Rst As ADODB.Recordset Dim Cmd As ADODB.Command Dim SQL As String Dim I As Integer Dim N As Integer
Select Case KeyCode Case vbKeyReturn If Grid.Rows <= 1 Then Exit Sub Dim K As Boolean K = Foot(lblSum.Caption, lblsums.Caption) If K = False Then Exit Sub
Conn.BeginTrans
Set Cmd = New ADODB.Command Cmd.ActiveConnection = Conn
Call ReSet Number = Number + 1 lbl.Caption = Format(Date$, "yymmdd") & "#" & Format(CStr(Number), "0000") Case vbKeyF3 Call ReSet Case vbKeyF4 If Grid.Rows = 1 Then Exit Sub txtNum.Top = Grid.Top + Grid.RowHeight(Grid.RowSel) * Grid.RowSel + 5 txtNum.Visible = True txtNum.SetFocus txtNum.Text = Grid.TextMatrix(Grid.RowSel, 7) txtNum.SelStart = 0 txtNum.SelLength = Len(txtNum.Text) Grid.Enabled = False Case vbKeyF5 If Grid.Rows = 1 Then Exit Sub txtZK.Top = Grid.Top + Grid.RowHeight(Grid.RowSel) * Grid.RowSel + 5 txtZK.Visible = True txtZK.SetFocus txtZK.Text = Grid.TextMatrix(Grid.RowSel, 8) txtZK.SelStart = 0 txtZK.SelLength = Len(txtZK.Text) Grid.Enabled = False Case vbKeyF6 fra.Visible = True Grid.Enabled = False txtTM.SetFocus Case vbKeyF7 ''单位 If Grid.Rows = 1 Then Exit Sub
Set Rst = New ADODB.Recordset SQL = "select unit from yaopin_unit where id='" & Grid.TextMatrix(Grid.RowSel, 1) & "'" Rst.Open SQL, Conn, adOpenStatic, adLockReadOnly, adCmdText If Rst.EOF Then Exit Sub
cobUnit.Clear For I = 1 To Rst.RecordCount cobUnit.AddItem Rst.Fields(0) Rst.MoveNext Next Set Rst = Nothing cobUnit.Top = Grid.Top + Grid.RowHeight(Grid.RowSel) * Grid.RowSel + 5 cobUnit.Visible = True cobUnit.SetFocus Grid.Enabled = False Case vbKeyF8 If Grid.Rows = 1 Then Exit Sub txtZ.Enabled = True txtZ.SelStart = 0 txtZ.SelLength = Len(txtZ.Text) txtZ.SetFocus Grid.Enabled = False Case vbKeyF9 If Grid.Rows > 1 Then Exit Sub frmBack.Show 1 Case vbKeyDelete, vbKeyBack Dim SumCash As Currency
If Grid.RowSel = 0 Then Exit Sub If Grid.Rows = 2 Then ReSet: Exit Sub IDList.Remove Grid.RowSel Grid.RemoveItem Grid.RowSel For I = 1 To Grid.Rows - 1 SumCash = SumCash + Val(Grid.TextMatrix(I, 10)) Next lblSum.Caption = Format(CStr(SumCash), ".00") lblsums.Caption = Format(CStr(SumCash) * IIf(Val(txtZ.Text) = 1, 1, Val(txtZ.Text) / 10), ".00")
For I = 1 To Grid.Rows - 1 Grid.TextMatrix(I, 0) = CStr(I) Next
End Select End SubPrivate Sub tmr_Timer() Dim I As Integertmr.Enabled = False If Id = "" Then Exit SubFor I = 1 To IDList.Count If Id = IDList(I) Then Grid.TextMatrix(I, 7) = CStr(Val(Grid.TextMatrix(I, 7)) + 1) Grid.TextMatrix(I, 10) = Format(CStr(Val(Grid.TextMatrix(I, 7)) * Grid.TextMatrix(I, 9)), ".00") GoTo ee End If NextDim Rst As ADODB.Recordset Dim CRst As ADODB.Recordset Dim SQL As String Dim SumCash As CurrencySQL = "select id,name,guige,changjia,unit,price from v_yaopin_list where tiaoma='" & Id & "' order by switch desc" Set Rst = New ADODB.Recordset Rst.CursorLocation = adUseClient Rst.Open SQL, Conn, adOpenStatic, adLockReadOnly, adCmdText If Rst.EOF Then Id = "": Exit SubSQL = "select * from yaopin_cost where id='" & Rst.Fields("id") & "'" Set CRst = New ADODB.Recordset CRst.CursorLocation = adUseClient CRst.Open SQL, Conn, adOpenDynamic, adLockReadOnly, adCmdText If CRst.EOF Then Exit Sub Set CRst = NothingGrid.Rows = Grid.Rows + 1 Grid.TextMatrix(Grid.Rows - 1, 0) = Grid.Rows - 1 Grid.TextMatrix(Grid.Rows - 1, 1) = Rst.Fields("id") Grid.TextMatrix(Grid.Rows - 1, 2) = Rst.Fields("name") Grid.TextMatrix(Grid.Rows - 1, 3) = Rst.Fields("guige") Grid.TextMatrix(Grid.Rows - 1, 4) = Rst.Fields("changjia") Grid.TextMatrix(Grid.Rows - 1, 5) = Rst.Fields("unit") Grid.TextMatrix(Grid.Rows - 1, 6) = Format(Rst.Fields("price"), ".00") Grid.TextMatrix(Grid.Rows - 1, 7) = "1" Grid.TextMatrix(Grid.Rows - 1, 8) = "1" Grid.TextMatrix(Grid.Rows - 1, 9) = Format(Rst.Fields("price"), ".00") Grid.TextMatrix(Grid.Rows - 1, 10) = Format(Rst.Fields("price"), ".00")Rst.Close Set Rst = NothingIDList.Add Idee:For I = 1 To Grid.Rows - 1 SumCash = SumCash + Val(Grid.TextMatrix(I, 10)) NextlblSum.Caption = Format(CStr(SumCash), ".00") lblsums.Caption = Format(CStr(SumCash) * IIf(Val(txtZ.Text) = 1, 1, Val(txtZ.Text) / 10), ".00")Id = ""End Sub
一把扫描枪可以设置返回字符串带不带vbcrlf
我们的做法是
sub textbox_keypress()
if ascii=13 then
if textbox.text 是合法条码 then
处理条码
end if
end if
end sub
Dim Rst As ADODB.Recordset
Dim Cmd As ADODB.Command
Dim SQL As String
Dim I As Integer
Dim N As Integer
Select Case KeyCode
Case vbKeyReturn
If Grid.Rows <= 1 Then Exit Sub
Dim K As Boolean
K = Foot(lblSum.Caption, lblsums.Caption)
If K = False Then Exit Sub
Conn.BeginTrans
Set Cmd = New ADODB.Command
Cmd.ActiveConnection = Conn
SQL = "insert into sell_index values ('" & lbl.Caption & "','" _
& Format(Date$, "yyyy-mm-dd") & "','" & Format(Time$, "hh:mm:ss") & "','" & _
UserName & "'," & lblSum.Caption & "," & txtZ.Text & "," & lblsums.Caption & ")"
Cmd.CommandText = SQL
Cmd.CommandType = adCmdText
Cmd.Execute
For I = 1 To Grid.Rows - 1
SQL = "execute selling '" & lbl.Caption & "','" & Grid.TextMatrix(I, 1) & "'," _
& Grid.TextMatrix(I, 6) & "," & Grid.TextMatrix(I, 8) & "," _
& Grid.TextMatrix(I, 9) & ",'" & Grid.TextMatrix(I, 5) & "'," & Grid.TextMatrix(I, 7)
Cmd.CommandText = SQL
Cmd.CommandType = adCmdText
Cmd.Execute
Next
Conn.CommitTrans
Call ReSet
Number = Number + 1
lbl.Caption = Format(Date$, "yymmdd") & "#" & Format(CStr(Number), "0000")
Case vbKeyF3
Call ReSet
Case vbKeyF4
If Grid.Rows = 1 Then Exit Sub
txtNum.Top = Grid.Top + Grid.RowHeight(Grid.RowSel) * Grid.RowSel + 5
txtNum.Visible = True
txtNum.SetFocus
txtNum.Text = Grid.TextMatrix(Grid.RowSel, 7)
txtNum.SelStart = 0
txtNum.SelLength = Len(txtNum.Text)
Grid.Enabled = False
Case vbKeyF5
If Grid.Rows = 1 Then Exit Sub
txtZK.Top = Grid.Top + Grid.RowHeight(Grid.RowSel) * Grid.RowSel + 5
txtZK.Visible = True
txtZK.SetFocus
txtZK.Text = Grid.TextMatrix(Grid.RowSel, 8)
txtZK.SelStart = 0
txtZK.SelLength = Len(txtZK.Text)
Grid.Enabled = False
Case vbKeyF6
fra.Visible = True
Grid.Enabled = False
txtTM.SetFocus
Case vbKeyF7
''单位
If Grid.Rows = 1 Then Exit Sub
Set Rst = New ADODB.Recordset
SQL = "select unit from yaopin_unit where id='" & Grid.TextMatrix(Grid.RowSel, 1) & "'"
Rst.Open SQL, Conn, adOpenStatic, adLockReadOnly, adCmdText
If Rst.EOF Then Exit Sub
cobUnit.Clear
For I = 1 To Rst.RecordCount
cobUnit.AddItem Rst.Fields(0)
Rst.MoveNext
Next
Set Rst = Nothing
cobUnit.Top = Grid.Top + Grid.RowHeight(Grid.RowSel) * Grid.RowSel + 5
cobUnit.Visible = True
cobUnit.SetFocus
Grid.Enabled = False
Case vbKeyF8
If Grid.Rows = 1 Then Exit Sub
txtZ.Enabled = True
txtZ.SelStart = 0
txtZ.SelLength = Len(txtZ.Text)
txtZ.SetFocus
Grid.Enabled = False
Case vbKeyF9
If Grid.Rows > 1 Then Exit Sub
frmBack.Show 1
Case vbKeyDelete, vbKeyBack
Dim SumCash As Currency
If Grid.RowSel = 0 Then Exit Sub
If Grid.Rows = 2 Then ReSet: Exit Sub
IDList.Remove Grid.RowSel
Grid.RemoveItem Grid.RowSel
For I = 1 To Grid.Rows - 1
SumCash = SumCash + Val(Grid.TextMatrix(I, 10))
Next
lblSum.Caption = Format(CStr(SumCash), ".00")
lblsums.Caption = Format(CStr(SumCash) * IIf(Val(txtZ.Text) = 1, 1, Val(txtZ.Text) / 10), ".00")
For I = 1 To Grid.Rows - 1
Grid.TextMatrix(I, 0) = CStr(I)
Next
End Select
End SubPrivate Sub tmr_Timer()
Dim I As Integertmr.Enabled = False
If Id = "" Then Exit SubFor I = 1 To IDList.Count
If Id = IDList(I) Then
Grid.TextMatrix(I, 7) = CStr(Val(Grid.TextMatrix(I, 7)) + 1)
Grid.TextMatrix(I, 10) = Format(CStr(Val(Grid.TextMatrix(I, 7)) * Grid.TextMatrix(I, 9)), ".00")
GoTo ee
End If
NextDim Rst As ADODB.Recordset
Dim CRst As ADODB.Recordset
Dim SQL As String
Dim SumCash As CurrencySQL = "select id,name,guige,changjia,unit,price from v_yaopin_list where tiaoma='" & Id & "' order by switch desc"
Set Rst = New ADODB.Recordset
Rst.CursorLocation = adUseClient
Rst.Open SQL, Conn, adOpenStatic, adLockReadOnly, adCmdText
If Rst.EOF Then Id = "": Exit SubSQL = "select * from yaopin_cost where id='" & Rst.Fields("id") & "'"
Set CRst = New ADODB.Recordset
CRst.CursorLocation = adUseClient
CRst.Open SQL, Conn, adOpenDynamic, adLockReadOnly, adCmdText
If CRst.EOF Then Exit Sub
Set CRst = NothingGrid.Rows = Grid.Rows + 1
Grid.TextMatrix(Grid.Rows - 1, 0) = Grid.Rows - 1
Grid.TextMatrix(Grid.Rows - 1, 1) = Rst.Fields("id")
Grid.TextMatrix(Grid.Rows - 1, 2) = Rst.Fields("name")
Grid.TextMatrix(Grid.Rows - 1, 3) = Rst.Fields("guige")
Grid.TextMatrix(Grid.Rows - 1, 4) = Rst.Fields("changjia")
Grid.TextMatrix(Grid.Rows - 1, 5) = Rst.Fields("unit")
Grid.TextMatrix(Grid.Rows - 1, 6) = Format(Rst.Fields("price"), ".00")
Grid.TextMatrix(Grid.Rows - 1, 7) = "1"
Grid.TextMatrix(Grid.Rows - 1, 8) = "1"
Grid.TextMatrix(Grid.Rows - 1, 9) = Format(Rst.Fields("price"), ".00")
Grid.TextMatrix(Grid.Rows - 1, 10) = Format(Rst.Fields("price"), ".00")Rst.Close
Set Rst = NothingIDList.Add Idee:For I = 1 To Grid.Rows - 1
SumCash = SumCash + Val(Grid.TextMatrix(I, 10))
NextlblSum.Caption = Format(CStr(SumCash), ".00")
lblsums.Caption = Format(CStr(SumCash) * IIf(Val(txtZ.Text) = 1, 1, Val(txtZ.Text) / 10), ".00")Id = ""End Sub