📄 publicmodule.bas
字号:
Attribute VB_Name = "publicmodule"
'******************数据库操作通用过程********************
Option Explicit
'加载数据库
Public Sub loadmdb(ado As Adodc)
Dim a As String
a = App.Path
ado.ConnectionString = "Provider=Microsoft.Jet.OLEDB.4.0;Data Source=" & a & "\library.mdb;Persist Security Info=False"
ado.CommandType = adCmdTable
ado.RecordSource = "书籍总表"
ado.Refresh
End Sub
'记录浏览
Public Sub explorrecord(ado As Adodc, dgrid As DataGrid, tablename As String)
ado.CommandType = adCmdTable
ado.RecordSource = tablename
ado.Refresh
dgrid.Caption = tablename
End Sub
'记录查询
Public Sub selectrecord(ado As Adodc, dgrid As DataGrid, tablename As String, wordname As String, serchtext As String)
ado.CommandType = adCmdText
ado.RecordSource = "select * from " & tablename & " where " & wordname & " like " & "'%" & serchtext & "%'"
ado.Refresh
dgrid.Caption = ""
End Sub
'确定符合特定条件的记录
Public Sub lockrecord(ado As Adodc, tablename As String, wordname As String, serchtext As String)
ado.CommandType = adCmdText
ado.RecordSource = "select * from " & tablename & " where " & wordname & " =" & "'" & serchtext & "'"
ado.Refresh
End Sub
'书籍自动编号
Public Function autobooknum(ado As Adodc, tablename As String) As String
Dim num As Long
ado.CommandType = adCmdTable
ado.RecordSource = tablename
ado.Refresh
ado.Recordset.MoveFirst
Do While Not ado.Recordset.EOF
If Val(ado.Recordset!书号) > num Then
num = Val(ado.Recordset!书号)
End If
ado.Recordset.MoveNext
Loop
autobooknum = CStr(num + 1)
End Function
'学生自动编号
Public Function autostudentnum(ado As Adodc, tablename As String) As String
Dim num As Long
ado.CommandType = adCmdTable
ado.RecordSource = tablename
ado.Refresh
ado.Recordset.MoveFirst
Do While Not ado.Recordset.EOF
If Val(ado.Recordset!学号) > num Then
num = Val(ado.Recordset!学号)
End If
ado.Recordset.MoveNext
Loop
autostudentnum = CStr(num + 1)
End Function
⌨️ 快捷键说明
复制代码
Ctrl + C
搜索代码
Ctrl + F
全屏模式
F11
切换主题
Ctrl + Shift + D
显示快捷键
?
增大字号
Ctrl + =
减小字号
Ctrl + -