Private Sub Form_Load()
On Error Resume Next
Set conn = CreateObject("ADODB.Connection")
conn.Open "Provider=Microsoft.Jet.OLEDB.4.0;Data Source=" & App.Path & "\数据库名称.mdb"
If Err Then
Err.Clear
Set conn = Nothing
Exit Sub
End If
Set rs = CreateObject("ADODB.Recordset")
SQL = "select * from 数据表名"
rs.Open SQL, conn, 1, 1
i = 1
Do While Not rs.EOF
Text1.Text = Text1.Text & vbCrLf & rs("列名")
rs.MoveNext
i = i + 1
Loop
rs.Close
Set rs = Nothing
conn.Close
Set conn = Nothing
End Sub
注意:如果你想要Text1出现滚动条的话,就设置它的Scrollbars为3 - both,同时设置MultiLine为True
测试结果如下图:
连接Access后,select 列明 from 表名
然后 rs.movefirst
do while not rs.eof
text1.text=text1.text+rs(0)+vbcrlf
rs.movenext
loop