Go Back  Xtreme Visual Basic Talk > Legacy Visual Basic (VB 4/5/6) > Database and Reporting > Problem reading a table from an open database


Reply
 
Thread Tools Display Modes
  #1  
Old 02-23-2001, 02:17 AM
jakes_72
Guest
 
Posts: n/a
Default Problem reading a table from an open database


I have managed so far to open my database, but the minute I try and link to my table with the following code:

Set testtable = testdatadb.OpenRecordset("mailing list")
or
Set testtable = testdatadb.OpenRecordset("SELECT * FROM [mailing list]")

I keep getting an error message saying the jet engine cant find the table. Is there something I'm missing? Can somebody run through with me the procedure of setting up a database in access 2000 as well, cause I use the wizard, and maybe I' m doing something wrong!

I'm not gonna give up, I'll get it right some day...... :-)

Reply With Quote
  #2  
Old 02-24-2001, 10:52 PM
cbrewer cbrewer is offline
Junior Contributor
 
Join Date: Aug 2000
Location: Florida
Posts: 163
Default 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.

Option Explicit
'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
'Bind controls
Dim txt As TextBox
Set txt = Text1
Set txt.DataSource = adoRS
txt.DataField = "field1"

End Sub

'When you are done using the connection
'Close Recordset and Connection
adoRS.Close
cn.Close

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>
Reply With Quote
Reply


Currently Active Users Viewing This Thread: 1 (0 members and 1 guests)
 
Thread Tools
Display Modes

Posting Rules
You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts

BB code is On
Smilies are On
[IMG] code is Off
HTML code is Off

Forum Jump

Advertisement:





Free Publications
The ASP.NET 2.0 Anthology
101 Essential Tips, Tricks & Hacks - Free 156 Page Preview. Learn the most practical features and best approaches for ASP.NET.
subscribe
Programmers Heaven C# School Book -Free 338 Page eBook
The Programmers Heaven C# School book covers the .NET framework and the C# language.
subscribe
Build Your Own ASP.NET 3.5 Web Site Using C# & VB, 3rd Edition - Free 219 Page Preview!
This comprehensive step-by-step guide will help get your database-driven ASP.NET web site up and running in no time..
subscribe
 
 
-->