02-24-2001, 10:52 PM
Join Date: Aug 2000
Re: Problem reading a table from an open database
There are a few different ways to open and access databases, here is an example using an Explicit Connection Object and early binding.
'Declare your connection and recordset variables in the general section
Dim cn As Connection
Dim adoRS As Recordset
Private Sub Command1_Click()
'Set up your connection
Set cn = New ADODB.Connection
cn.Open "PROVIDER=Microsoft.Jet.OLEDB.3.51;Data Source=YourDatabase.mdb;"
'Set up your recordset
Set adoRS = New ADODB.Recordset
adoRS.Open "Select field1, field2, field3 from Table", cn
Dim txt As TextBox
Set txt = Text1
Set txt.DataSource = adoRS
txt.DataField = "field1"
'When you are done using the connection
'Close Recordset and Connection
This is the recommended method and is used in the wizards which Microsoft built, unless you need to use late binding for some reason, or in the very unlikely event you need to implicily open a connection (the implicit connection only lets each connection string to have one recordsource open at once).
Change the connection string to reflect MS Access 2000 jet drivers, I think it is Microsoft.Jet.OLEDB.3.6
Chuck<P ID="edit"><FONT SIZE=-1><EM>Edited by cbrewer on 02/24/01 11:54 PM (server time).</EM></FONT></P>