connection acess database

Public Schedule Face-to-Face & Online Instructor-Led Training - View dates & book

Forum home » Delegate support and help forum » Microsoft Excel Training and help » Connection to an acess database

Connection to an acess database

resolvedResolved · High Priority · Version 2007

jeff has attended:
Excel VBA Intro Intermediate course

Connection to an acess database

I am trying to connect to an access database. I have successfully created the udl and tested its connection but have fallen at the next hurdle. When I try to run my script it errors on the line "Dim cnConnection As ADoDB.connnection" with Compile error: User-defined type not defined. The script up to the point it fails is shown below:

Sub ImportAmbients()
'18/11/09 JCalam Scrip to import the ambient contitions from the balance database.

Const ConString As String = _
"Provider=MSDASQL.1;Password=buttman;Persist Security Info=True;Data Source=BalanceData;Mode=Read;Initial Catalog=C:\BalBase\Bal32Base"

Dim cnConnection As ADODB.Connection

'I am pretty sure it is related to be not having the required add in or dll installed. When we did out course we had to enable and add in or option. Any help would be greatly appreciated.

Jeff

RE: Connection to an acess database

Hi Jeff

Thanks for your question

You need to set a reference to the activeX data objects library.

In the VBE click on Tools , References

You will see a list of possible references, with the ones currently set having a tick against them. If "active x dataobjects 2.8 library" is not ticked, you will need to scroll down until you find it and tick it. (Note the number 2.8 may differ on your machine, if it does choose the nearest matching number)

If this do9esn't solve the problem please get back to me

Regards

Stephen


 

Excel tip:

Select only cell that contain text to lock format

For selecting cells that only contain Text in Excel

By selecting cells that only contain text, you can delete, fill or protect cells of this type.

Use short cut to Go to box (F5) or Edit, Go to
In the dialog box, click special button & select Constants and only check text or any other desired type.

Click OK.

And text cells will all be highlighted for you to apply format. Please note only works on one sheet at a time.

View all Excel hints and tips


Server loaded in 0.09 secs.