提示BOF惑EOF中有一个是“真”或者当前记录已被删除,所需的操作要求一个当前的记录
[color=#FF0000]Dim Prices As Single '定义一个计算价格的变量Dim i As Integer '运用在FOR循环中的变量
Dim StrTemp '用于显示编号信息的变量
Dim StrNum As Long '用于显示编号信息的变量
Dim ETemp As Integer '定义一个日志标识变量
'*** “删除”商品出库信息按钮的事件过程 ***
Private Sub Cmd_del_Click()
rtn = SetWindowPos(Me.hwnd, -2, 0, 0, 0, 0, 3) '运用API函数SetWindowPos,来实现取消窗体置前的功能
If Adodc1.Recordset.EOF = False Then
c = MsgBox("您确认要删除该记录吗?", 17)
If c = vbOK Then
Adodc1.Recordset.Delete '删除货品出库信息记录
Adodc1.Refresh
Call Main
adoRs.Open "select * from spxx where xh='" + Text1(1).Text + "'", adoCon, adOpenKeyset
If adoRs.RecordCount > 0 Then
Dim SNum As Integer
'重新计算库存货品的数量
SNum = Val(adoRs.Fields("kcl")) + Val(Text1(4).Text)
'修改该货品的库存数量
Set adoRs = adoCon.Execute("UPDATE spxx SET kcl='" + Str(SNum) + "' where xh='" + Text1(1).Text + "' ")
End If
adoCon.Close
For i = 0 To 6 '清空文本框中的内容
Text1(i).Text = ""
Next i
'Cmd_del.Enabled = False
End If
Else
MsgBox "当前数据库中已经没有可删除的记录", 64
End If
Call TRefresh
End Sub
Private Sub Cmd_exit_Click()
Unload Me
End Sub
'*** “保存”货品出库信息按钮的事件过程 ***
Private Sub Cmd_save_Click()
rtn = SetWindowPos(Me.hwnd, -2, 0, 0, 0, 0, 3) '运用API函数SetWindowPos,来实现取消窗体置前的功能
Adodc1.RecordSource = "select * from ckgl where dh=" + Text1(0).Text '判断所要保存的信息是否已经存在
Adodc1.Refresh
If Adodc1.Recordset.RecordCount > 0 Then
MsgBox "该信息已经存在,信息保存不成功", 64
Call TRefresh '调用数据刷新的过程
Else
c = MsgBox("您确认要保存该信息吗?", 33)
If c = vbOK Then
If Text1(1).Text = "" Or Text1(3).Text = "" Or Text1(4).Text = "" Or Text2.Text = "" Then
MsgBox "货品数量、单价、名称或者提货人信息不能为空值!", 48
Else
'IsNumeric函数用于判断输入的信息是否为数值型数据
If Not IsNumeric(Text1(3).Text) Or Not IsNumeric(Text1(4).Text) Then
MsgBox "输入的货品数量或单价必须为数值型数据", 48
Else
Call Main '调用公共模块中的连接数据库函数
adoRs.Open "select * from spxx where xh='" + Text1(1).Text + "'", adoCon, adOpenKeyset
If adoRs.RecordCount > 0 Then
Dim SNum As Integer
SNum = Val(adoRs.Fields("kcl")) - Val(Text1(4).Text) '计算库存中相应货品的数量
If SNum >= 0 Then
'修改库存中货品的数量
Set adoRs = adoCon.Execute("UPDATE spxx SET kcl='" + Str(SNum) + "' where xh='" + Text1(1).Text + "'")
'保存货品出库信息
Set adoRs = adoCon.Execute("insert into ckgl (dh,rq,bh,spmc,gg,xssl,xsjg,bz,ghsbh,ghsmc,czy) values(" & Text1(0).Text & ",'" & DTPicker1.Value & "','" & Text1(1).Text & "','" & Text1(2).Text & "','" & Text1(3).Text & "','" & Text1(4).Text & "','" & Text1(5).Text & "','" & Text1(6).Text & "','" & Text2.Text & "','" & Text3.Text & "','" & Text4.Text & "')")
MsgBox "信息保存成功", 64
Adodc1.RecordSource = "select kc_down from kcbjxx where mc='" + Text1(2).Text + "'"
Adodc1.Refresh
Adodc1.Recordset.MoveFirst
If Adodc1.Recordset.Fields(0) >= SNum Then
MsgBox "库存不足"
End If
'Cmd_save.Enabled = False
Else
Dim Strs As String
Strs = "该货品的库存数量为 " & adoRs.Fields("kcl") & " ,货品出库数量不应大于其库存数量"
MsgBox Strs, 48
End If
End If
adoCon.Close '关闭数据连接
End If
End If
Else
End If
End If
Call TRefresh '调用数据刷新过程
End Sub
Private Sub Combo1_KeyDown(KeyCode As Integer, Shift As Integer)
If KeyCode = 13 Then '如果按下的是回车键,则光标落到文本框当中
Text1(3).SetFocus
End If
End Sub
Private Sub DataGrid1_Click()
Call JionBack '调用数据反绑定过程 '调用数据反绑定过程
' Cmd_del.Enabled = True
'Cmd_save.Enabled = False
End Sub
Private Sub DTPicker1_KeyDown(KeyCode As Integer, Shift As Integer)
If KeyCode = 13 Then '如果按下的是回车键,则光标落到文本框当中
Text1(5).SetFocus
End If
End Sub
Private Sub Form_Load()
rtn = SetWindowPos(Me.hwnd, -1, 0, 0, 0, 0, 3) '运用API函数SetWindowPos,来实现使窗体置前的功能
'利用代码连接数据库
Adodc1.ConnectionString = CnnStr
Adodc1.RecordSource = "select * from ckgl" '连接出库信息数据表
Adodc1.Refresh
Me.Left = (Screen.Width - Me.Width) / 2 '使窗体居中
Me.Top = (Screen.Height - Me.Height) / 2
DTPicker1.Value = Date
End Sub
Private Sub Frame1_DragDrop(Source As Control, X As Single, Y As Single)
End Sub
Private Sub Text1_KeyDown(Index As Integer, KeyCode As Integer, Shift As Integer)
If KeyCode = 13 Then
If Index = 1 Then '如果是第2个文本框,则调用frm_Tout窗体
frm_Tout.Show
frm_Tout.Left = 4100
frm_Tout.Top = 2750
frm_Tout.DataGrid1.SetFocus
ElseIf Index = 1 Then
Text1(2).SetFocus
ElseIf Index = 2 Then
Text1(3).SetFocus
ElseIf Index = 3 Then
Text1(4).SetFocus
ElseIf Index = 4 Then
DTPicker1.SetFocus
ElseIf Index = 5 Then
Text2.SetFocus
End If
End If
End Sub
Private Sub Text2_KeyDown(KeyCode As Integer, Shift As Integer)
If KeyCode = 13 Then
Text3.SetFocus
End If
End Sub
'Private Sub Timer1_Timer() '通过时钟控件随时检测数据库中记录的条数
'If Adodc1.Recordset.RecordCount > 0 Then
'Label9.Caption = "目前数据库易做图有 " & Adodc1.Recordset.RecordCount & " 条出库数据"
'End If
'End Sub
'*** 自定义的数据反绑定过程 ***
Private Sub JionBack()
Dim SLen As Integer
If Adodc1.Recordset.RecordCount > 0 Then
On Error Resume Next '执行错误处理
Text1(0).Text = Adodc1.Recordset(0)
Text1(1).Text = Adodc1.Recordset(2)
Text1(2).Text = Adodc1.Recordset(3)
Text1(3).Text = Adodc1.Recordset(4)
Text1(4).Text = Adodc1.Recordset(5)
Text1(5).Text = Adodc1.Recordset(6)
DTPicker1.Value = Adodc1.Recordset(2)
Text1(6).Text = Adodc1.Recordset(10)
Text2.Text = Adodc1.Recordset.Fields("ghsbh")
Text3.Text = Adodc1.Recordset.Fields("ghsmc")
Text4.Text = Adodc1.Recordset.Fields("czy")
End If
End Sub
'*** 自定义的数据刷新过程 ***
Private Sub TRefresh()
Adodc1.RecordSource = "select * from ckgl order by dh"
Adodc1.Refresh
End Sub
Private Sub Form_Unload(Cancel As Integer)
frm_main.Enabled = True '在窗体关闭的时候使主窗体可用End Sub[/color]
帮忙看看这个有问题么 --------------------编程问答-------------------- sql有错,没有返回记录。 --------------------编程问答-------------------- 这样的问题,一般是没有找到数据,才会提示。
在查询数据完成以后,加个判断。
打印一下SQL语句
If adoRs.eof then
msgbox "没有找到数据"
msgbox sql
exit sub
end if
补充:VB , 基础类