Discussion Locked

Databaseconnection in VBA.

0 helpful
5 replies
Closed to new repliesThis discussion is closed. It stays readable, but it takes no new replies.

How do I connect to a database (I.e. Exchange 5.5 or an Access database), gathering information like phonenumbers or addresses, and put it into a userform object like a textbox?? This need to be done without fields in a document and mailmerge!!!
App.: Word 2000.
Thx!!

5 replies

by donq

Your question (as explained) has MANY possibilities:

If you are connecting to an Access database use the DAO subset of VBA code to link with your data source.

If you are connecting to an ODBC database use the ADO subset of VBA code to link with your data source.

If you are attempting to gather more than one thing (many times) you will need many text bboxes each lonked with a unique data source object.

The actual code is very simple and reads much like

Dim db As Database
Set db =CurrentDb()

however only you know the names of the objects holding the "source" data and the name of your "target" field(s)??

Sorry I can't help more but you didn't provide ANY specifics.

by a.c

DAO (Data Access Objects)

Use the OpenDatabase method to connect to a database and open it. After opening the database, use the OpenRecordset method to access a table or query for results. To navigate through the recordset, use the Move method.To find a specific record, use the Seek method. If you need only a subset of records instead of the entire recordset, use the CreateQueryDef method to design a customized query to select records that meet your criteria. When you finish working with a database, close it using the Close method.

Have a look at the VBA help, search for "database connection" and have a look at some of the example code

This discussion is closed to new replies.