VB+access还书窗体代码第2部分,希望高手帮忙详细解释下,谢谢

发布网友 发布时间:2024-10-24 00:28

我来回答

1个回答

热心网友 时间:2024-10-30 21:23

Private Sub Command1_Click() 'command1应该是还书按扭
Dim book_num As String
Dim reader_num As String
Dim answer As String
Dim rs_back As New ADODB.Recordset
Dim sql As String '以上为定义
On Error GoTo delerror '如果错误跳转
book_num = DataGrid1.Columns(3).CellValue(DataGrid1.Bookmark) '书籍编号等于所选行第4列值
reader_num = DataGrid1.Columns(1).CellValue(DataGrid1.Bookmark) 读者编号等于所选行第2列值

answer = MsgBox("确定要还这本书吗?", vbYesNo, "") '问是否还书
If answer = vbYes Then
sql = "select * from 图书借阅表 where 书籍编号='" & book_num & "'"
rs_back.CursorLocation = adUseClient
rs_back.Open sql, conn, adOpenKeyset, adLockPessimistic
rs_back.Delete
rs_back.Update
rs_back.Close '以上是根据书籍编号从图书借阅表中把该书找出来,然后删除.
sql = "select * from 图书登记表 where 书籍编号='" & book_num & "'"
rs_back.CursorLocation = adUseClient
rs_back.Open sql, conn, adOpenKeyset, adLockPessimistic
rs_back.Fields(7) = "否"
rs_back.Update
rs_back.Close '以上是根据书籍编号从图书登记表中把该书的借阅状态改为"否"
sql = "select * from 读者信息 where 读者编号='" & reader_num & "'"
rs_back.CursorLocation = adUseClient
rs_back.Open sql, conn, adOpenKeyset, adLockPessimistic
rs_back.Fields(8) = rs_back.Fields(8) - 1
rs_back.Update
rs_back.Close '以上是根据读者编号把该读者的信息找出来然后把该人的借书数量减少一本.
If findform = True Then 'findform应该是定义的一个全局变量,如果为真
Command3_Click '执行Command3_Click
Else '否则
Command4_Click '执行Command4_Click
End If
MsgBox "操作成功!", vbOKOnly + vbExclamation, ""
DataGrid1.AllowDelete = False
Else
Exit Sub
End If
delerror:
If Err.Number <> 0 Then
MsgBox Err.Description
End If

End Sub

Private Sub Command2_Click() '退出
Unload Me
End Sub

Private Sub Form_Load() Dim rs_reader As New ADODB.Recordset
Dim rs_book As New ADODB.Recordset
Dim sql As String
sql = "select * from 读者信息"
rs_reader.CursorLocation = adUseClient
rs_reader.Open sql, conn, adOpenKeyset, adLockPessimistic
If Not rs_reader.EOF Then
Do While Not rs_reader.EOF
Combo1.AddItem rs_reader.Fields(1)
Combo2.AddItem rs_reader.Fields(0)
rs_reader.MoveNext
Loop
End If
rs_reader.Close '在窗口加载是把读者
信息里的两项分别加载到combo1和combo2中
sql = "select * from 图书借阅表"
rs_book.CursorLocation = adUseClient
rs_book.Open sql, conn, adOpenKeyset, adLockPessimistic
If Not rs_book.EOF Then
Do While Not rs_book.EOF
Combo3.AddItem rs_book.Fields(3)
Combo4.AddItem rs_book.Fields(4)
rs_book.MoveNext
Loop
End If
rs_book.Close
'在窗口加载是把书籍
信息里的两项分别加载到combo3和combo4中
End Sub

声明声明:本网页内容为用户发布,旨在传播知识,不代表本网认同其观点,若有侵权等问题请及时与本网联系,我们将在第一时间删除处理。E-MAIL:11247931@qq.com