2024-06-07 04:05:54
有多种连接方式,可以用数据控件连接,也可以用组件连接。下面是用ADO组件来连接的例子(假定ACCESS数据库文件和程序是放在同一个文件夹的):
Private Sub Form_Click() '点击窗体运行
Dim conn As Object, rs As Object
Set conn = CreateObject("Adodb.Connection")
conn.Open "provider=Microsoft.Jet.OLEDB.4.0; Data Source=" & App.Path & "\a.mdb"
Set rs = CreateObject("Adodb.Recordset")
rs.Open "select * from b", conn, 1, 1
Do Until rs.EOF
'这里是循环列出表b中的每条记录,熟悉的人就知道怎么做了
rs.MoveNext
Loop
rs.Close
Set rs = Nothing
conn.Close
Set conn = Nothing
End Sub