Moudle是模块,主要是为了方便一些公共函数的调用而设计的. 你可以在模块里面声明全局变量和结构,函数等等 简单的数据库连接方法 Dim db1 As Database Dim cd As Recordset Dim i As Single Set db1 = OpenDatabase(App.Path + "./login.mdb") Set cd = db1.OpenRecordset("select * from login where number=1") For i = 0 To 9 If IsNull(cd.Fields(i).value) = True Then Text1(i).Text = "" GoTo inerr End If Text1(i).Text = cd.Fields(i).value inerr: Next i Text1(10).Text = cd!username Text1(11).Text = cd!Password cd.Close db1.Close
你可以在模块里面声明全局变量和结构,函数等等
简单的数据库连接方法
Dim db1 As Database
Dim cd As Recordset
Dim i As Single
Set db1 = OpenDatabase(App.Path + "./login.mdb")
Set cd = db1.OpenRecordset("select * from login where number=1")
For i = 0 To 9
If IsNull(cd.Fields(i).value) = True Then
Text1(i).Text = ""
GoTo inerr
End If
Text1(i).Text = cd.Fields(i).value
inerr:
Next i
Text1(10).Text = cd!username
Text1(11).Text = cd!Password
cd.Close
db1.Close
Conn.Open "Driver={Microsoft Access Driver (*.mdb)};" & _
"Dbq=c:\somepath\mydb.mdb;" & _
"Uid=Admin;" & _
"Pwd=;" ACCESS数据库是ADO对象所用Jet Engine的内部数据库,最好不用ODBC:
Conn.Open "Driver=Microsoft.Jet.OLEDB.4.0;" & _
"Dbq=c:\somepath\mydb.mdb;" & _
"Uid=Admin;" & _
"Pwd=;"
你写一个联接函数,用sub main()调用它,在工程中将启动设为sub main()
connection对象一直开着,直到程序结束时然后再调用一个释放其资源的函数.
recordset最好也只有一个,使用时最好封装在一个过程或者函数中,使用完了注意函数结束时马上关掉.