Here is a small example with comments. Requires Listbox (List1) and Command Button (Command1):
In this example I'm using Northwind database and a table called Employees.Code:Private Sub Command1_Click() Dim cn As New ADODB.Connection 'Connection object Dim rs As New ADODB.Recordset 'Recordset object Dim strDBPath As String strDBPath = "C:\Program Files\Microsoft Visual Studio\VB98\Nwind.mdb" 'Set the native OLEDB provider for Jet (Access database) cn.Provider = "Microsoft.Jet.OLEDB.3.51" 'Open connection for Northwind database, where the UserID is Admin and no password cn.Open strDBPath, "admin", "" 'Open recordset for the Employees table rs.Open "Select * from Employees", cn, adOpenStatic 'Populate the Listbox with last and first names Do Until rs.EOF List1.AddItem rs(1) & ", " & rs(2) rs.MoveNext Loop rs.Close Set rs = Nothing cn.Close Set cn = Nothing End Sub
------------------
Serge
Software Developer
[email protected]
ICQ#: 51055819




Reply With Quote