Need help connecting to DB

J

J. Adams

We just moved from Office 97 to Office 2002. We have not
yet purchased the appropriate reference material so I am
stuck. In Office 97 I had an Excel file that gets data
from an Access database using the DAO - OpenDatabase
method.

Anyway, the code I used in 97 to open the database and
recordset so I can get the data I need does not seem to
work in 2002. I keep getting error "429", "Active X
component can't create object".

I looked through the available help files and the only
thing I could see that was different from Excel 97 was
that I needed to create a Workspace object. I tried using
the example from the help file but I still keep getting
that same error. I tried adding references to Access 10
Library but that won't work either. Below is a sample of
my code. Any help I could get on this would be greatly
appreciated.

Before I changed any code it would crap out at the
OpenDatabase statement. After I altered the code to
include the creation of a workspace it craps out at the
CreateWorkspace line..

Here it is, Note: some of the code has been changed to
protect the innocent

Private Function GetDatabaseData() As Boolean
'purpose: gets data from database
'accepts: none
'returns: true - if data is imported correctly
'declarations
Dim DB1 As Database, lsDBName As String, rst As
Recordset, lsSql As String
Dim wrkJet As Workspace

On Error GoTo ErrorHandler:

'equate fcn value
GetDatabaseData = False

'open database
Set wrkJet = CreateWorkspace("", "admin", "", dbUseJet)
lsDBName = "Y:\Shared\Test1\Test2\Test3.mdb"
Set DB1 = wrkJet.OpenDatabase(lsDBName)

'set sql statement, open recordset
lsSql = "SELECT yada yada yada
Set rst = DB1.OpenRecordset(lsSql, dbOpenSnapshot)

'dump recordset onto spreadsheet
'code to dump and massage and close recordset placed here

'close database variables, equate fcn value
rst.Close
DB1.Close
wrkJet.Close

GetDatabaseData = True
Exit Function

'error handling procedures
ErrorHandler:
'Code to handle error placed here

End Function

Thanking you in advance..
 
J

Jeff Boyce

Access 2000 (and 2002), by default, have NO reference set to the DAO object,
instead pointing to ADO. Both of these have "database" objects, but, if I
recall, the ADO object does not have a "Recordset".

Open a code module, select Tools & References, and check the MS DAO 3.61
object. Move it above the ADO reference, or uncheck that reference if you
aren't using ADO.

And for the future, any time you have to define objects that might be in
both, fully qualify which one, as in:

Dim db As DAO.Database
Dim rs As DAO.Recordset

Of course, this will only work if you have a reference to DAO!
 
J

J. Adams

-----Original Message-----
Access 2000 (and 2002), by default, have NO reference set to the DAO object,
instead pointing to ADO. Both of these have "database" objects, but, if I
recall, the ADO object does not have a "Recordset".

Open a code module, select Tools & References, and check the MS DAO 3.61
object. Move it above the ADO reference, or uncheck that reference if you
aren't using ADO.

And for the future, any time you have to define objects that might be in
both, fully qualify which one, as in:

Dim db As DAO.Database
Dim rs As DAO.Recordset

Of course, this will only work if you have a reference to DAO!

--
Good luck

Jeff Boyce
<Access MVP>

.
Thanks Jeff, it now works!! I guess I'll have to start
using ADO on future projects to avoid the hastle..
 
D

Douglas J. Steele

Jeff Boyce said:
Access 2000 (and 2002), by default, have NO reference set to the DAO object,
instead pointing to ADO. Both of these have "database" objects, but, if I
recall, the ADO object does not have a "Recordset".

Other way around, Jeff. There's no Database object in ADO, but there's a
Recordset object in both.
 
D

Douglas J. Steele

Thanks Jeff, it now works!! I guess I'll have to start
using ADO on future projects to avoid the hastle..

DAO is still the better method if you're strictly going against a Jet
database (an MDB file).
 
T

Tony Toews

I guess I'll have to start
using ADO on future projects to avoid the hastle..

Not at all. If you're comfortable with DAO stay with it.

Tony
--
Tony Toews, Microsoft Access MVP
Please respond only in the newsgroups so that others can
read the entire thread of messages.
Microsoft Access Links, Hints, Tips & Accounting Systems at
http://www.granite.ab.ca/accsmstr.htm
 
J

Jeff Boyce

Thanks, Doug!

<scratch, scratch, scratch ... I knew something was different, just couldn't
recall which!>

Jeff Boyce
<Access MVP>
 

Ask a Question

Want to reply to this thread or ask your own question?

You'll need to choose a username for the site, which only take a couple of moments. After that, you can post your question and our members will help you out.

Ask a Question

Similar Threads


Top