求助一个关于数据操作的问题,各位帮帮忙。

孤独勇敢洗衣机 技术经理  2010-10-09 01:26:56
程序要实现功能:图书的还入
当我单击cmd1的时候 程序搜索相关图书记录和借者记录并显示。
单击cmd2的时候 实现图书还入
2个data 控件
data1绑定的是 表图书信息 data2是借者信息

问题是这样的:
当我第一次搜索图书时候 没问题 显示了相关信息 然后我点归还图书 也没问题
但是我在还书后 第2次搜索图书的时候 就出错了 错误是:无当前记录
点调试 代码定位在Text7.DataField = "借书日期"这里
代码如下:

Private Sub Command1_Click()
Command2.Enabled = True
If Text1.Text = "" Or Text10.Text = "" Then
MsgBox "资料名字或借者名字不能为空", , "提示"
Exit Sub
Else
Text2.DataField = "编号"
Text3.DataField = "价格"
Text5.DataField = "名字"
Text6.DataField = "出版社"
Text7.DataField = "借书日期"
Text9.DataField = "限还日期"
Text11.DataField = "名字"
Text12.DataField = "总量"
Text13.DataField = "已借数量"


Text8.Text = Date
Data1.Recordset.MoveFirst
Data2.Recordset.MoveFirst
Data1.Recordset.FindFirst " 名字='" & Text1.Text & "'" '图书名字段为”名字“,借者名字段也为"名字"
Data2.Recordset.FindFirst " 已借图书='" & Text1.Text & "' And 名字='" & Text10.Text & "'"

End If
If Data2.Recordset.NoMatch Then
Text2.Text = ""
Text3.Text = ""

Text5.Text = ""
Text7.Text = ""
Text6.Text = ""
Text8.Text = ""
Text9.Text = ""
Text11.Text = ""
Text12.Text = ""
Text13.Text = ""
MsgBox "数据库中没有这本图书!", vbOKOnly + vbExclamation, "警告"
Command2.Enabled = False
End If

End Sub


Private Sub Command2_Click()
a = MsgBox("你确定还此书吗?", vbYesNo + vbQuestion, "提示")
If a = vbYes Then
Data2.Recordset.Delete
Text12.Text = Str(Val(Text12.Text) + 1)
Text13.Text = Str(Val(Text13.Text) - 1)

Data1.Recordset.Edit


Text2.Text = ""
Text3.Text = ""

Text5.Text = ""
Text7.Text = ""
Text6.Text = ""
Text8.Text = ""
Text9.Text = ""
Text11.Text = ""
Text12.Text = ""
Text13.Text = ""
Text1.Text = ""
Text10.Text = ""
Command2.Enabled = False



End If
End Sub

Private Sub Command7_Click()
Me.Hide
End Sub

Private Sub Form_Activate()
Text2.Text = ""
Text3.Text = ""

Text5.Text = ""
Text7.Text = ""
Text6.Text = ""
Text8.Text = ""
Text9.Text = ""
Text11.Text = ""
Text12.Text = ""
Text13.Text = ""
Text1.Text = ""
Text10.Text = ""
' Data1.Recordset.Update
' Data2.Recordset.Update
End Sub

Private Sub Form_Load()
Command2.Enabled = False
'Text13.Visible = False
'Text12.Visible = False
Data2.Visible = False
Data1.Visible = False
If Right(App.Path, 1) = "\" Then
Data1.DatabaseName = App.Path + "数据库.mdb"
Else
Data1.DatabaseName = App.Path + "\数据库.mdb"
End If
If Right(App.Path, 1) = "\" Then
Data2.DatabaseName = App.Path + "数据库.mdb"
Else
Data2.DatabaseName = App.Path + "\数据库.mdb"
End If
Data1.RecordSource = "图书信息"
Data2.RecordSource = "借者信息"

Data1.Refresh
Data2.Refresh


End Sub

找了半天 没发现错哪
求各位帮忙
先谢谢啦!
...全文
42 4 点赞 打赏 收藏 举报
写回复
4 条回复
切换为时间正序
当前发帖距今超过3年,不再开放新的回复
发表回复
呵呵 解决了 确实要刷新一下
  • 打赏
  • 举报
回复
luofenghen 2010-10-09
刷新一下
  • 打赏
  • 举报
回复
没人吗?自己顶下
  • 打赏
  • 举报
回复
相关推荐
发帖

1188

社区成员

VB 数据库(包含打印,安装,报表)
申请成为版主
帖子事件
创建了帖子
2010-10-09 01:26
社区公告
暂无公告