Conection

Conection

nucliabrasil
Advocate Advocate
1,706 Views
6 Replies
Message 1 of 7

Conection

nucliabrasil
Advocate
Advocate

Hello fellows!
Is there any way to connect the access of office 2010, using the vba in the civil 3dcad autocad 2016 64bits?
If it exists, how to do since the ado component is not shown in the vba reference list?

Thanks!

0 Likes
1,707 Views
6 Replies
Replies (6)
Message 2 of 7

norman.yuan
Mentor
Mentor

When you say "connect to (MS) Access..." you need to be more specific: connecting to MS Access application (COM automation, MS Access install is required), or connect to the *.acdbx/*.mdb file (for data only)? Let's assume your case is the latter.

 

ADO (Microsoft ActiveX Data Object 2.x) comes with Windows OS (both 32-bit and 64-bit). And you should see them in AutoCAD/Civil (64-bit) VBA's "Referneces" dialog box:

References To Ado.png

Since your AutoCAD is 64-bit, you must download/install MS Access DB Engine 64-bit from MS, which is very tricky/difficult if the computer has 32-bit MS Office installed. In many cases, it might be worth of the effort. Or, you have the computer install 64-bit MS Office (if MS Office is required by the user).

 

Norman Yuan

Drive CAD With Code

EESignature

0 Likes
Message 3 of 7

nucliabrasil
Advocate
Advocate

All right, my friend. I have all the ODBC drivers installed. The architecture is 64bit. Windows installed is Windows 10 and MS Office installed is 2016.
To connect with Access 2016, would it be enough to configure the Microsoft Activex Data Objects 2.8 Library reference library?
What would the connection syntax look like?
Thank you very much in advance.

 

0 Likes
Message 4 of 7

nucliabrasil
Advocate
Advocate

Take a look to my instaled drivers...

 

0 Likes
Message 5 of 7

norman.yuan
Mentor
Mentor

It looks look you have MS Access DB Engine 64-bit installed. You can do ahead to write code to connect to *.mdb/*.accdb with ADO, or DAO (older technology, if you prefer for certain reason, such as re-using existing old code).

 

The picture you showed is for creating ODBC data source, which you may or may not have to do: the ADO connection can be either connected via ODBC data source name (thus, you need to create DSN on each computer that runs your program), or connected via OleDB provider.

 

To use ODBC DSN (data source name), you create either a user DSN or a system DSN (usually system DSN, so that any user logged into that computer would be able to reach it). In "System DSN" tab, click "Add" button and follow the wizard to create a DSN that connect to the target *.mdb/*.accdb file. Once the DSN is created, the ADO.Connection's uses the DSN as its connection string, something like

 

Dim conn As AdoDb.Connection

Set conn = new AdoDb.Connection

conn.Open "myDsn"

 

As you can see, using ODBC DSN is like hard-coded database file name, which is not very flexible. It is recommended DSN-less connection, that is, with ConnectionString specifying data provider/driver, data source and security information, usually OleDb provider (ODBC provider can also be used, if you choose so). You can search the Internet for the connection string to connect *.mdb/*.accdb. BUt the simple way to do/learn it would be go through these steps:

 

1. Create a blank *.txt file with NotePad;

2. Rename the file to *.udl file;

3. Double-click the *.udl file, which would open "Data Link Properties" dialog;

4. Follow it to create a data link to *.mdb/*accdb with MS Access OldDb Provider;

5. Close the dialog once the connection is tested OK;

6. Open the *.udl file in NotePad, you would see a full valid ConnectionString that you can use for AdoDb.Connection.

 

I am not sure how much experience you have with database, but judging from your previous posts, I'd say, unless your work is mainly limited to maintain existing VBA code that is still mission critical and you are sure the only issue in 64-bit AutoCAD is the database connection, you may not want to spend (and eventually waste) too much time on 64-bit VBA with potentially complicated, mission-critical development. With external data/database involved, a development would quickly raise the need for good UI design or need other component support, which 64-bit VBA lacks of.  If anyone need to learn database programming, I'd recommend do it in .NET (well, then you need to learn AutoCAD .NET API).

 

 

Norman Yuan

Drive CAD With Code

EESignature

0 Likes
Message 6 of 7

nucliabrasil
Advocate
Advocate

Obrigado por me responder....mas estou com um problema grave de fatal error todas as vezes que tento conectar minha base access 2016.

 

0 Likes
Message 7 of 7

nucliabrasil
Advocate
Advocate

I was able to resolve this issue.

Thank you all.

0 Likes