Private Sub Form_Load()
Dim tabs(1 To 2) As Long
Dim db_file As String
Dim conn As ADODB.Connection
Dim rs As ADODB.Recordset
Dim txt As String
Dim fld As Field
' Set tabs in the ListBox.
tabs(1) = 20
tabs(2) = 130
' Set the tabs.
SendMessage List1.hwnd, LB_SETTABSTOPS, 2, tabs(1)
' Get the data.
db_file = App.Path
If Right$(db_file, 1) <> "\" Then db_file = db_file & _
"\"
db_file = db_file & "books.mdb"
' Open a connection.
Set conn = New ADODB.Connection
conn.ConnectionString = _
"Provider=Microsoft.Jet.OLEDB.4.0;" & _
"Data Source=" & db_file & ";" & _
"Persist Security Info=False"
conn.Open
' Open the Recordset.
Set rs = conn.Execute("SELECT * FROM Books", , _
adCmdText)
' List the data.
Do While Not rs.EOF
txt = ""
For Each fld In rs.Fields
txt = txt & Trim$(fld.Value) & vbTab
Next fld
If Len(txt) > 0 Then txt = Left$(txt, Len(txt) - 1)
List1.AddItem txt
rs.MoveNext
Loop
rs.Close
conn.Close
End Sub
|