Connecting to Microsoft Access with ADO - Read the connection string from the file
(Page 4 of 6 )
In reality the UDL file that was created is a text file. Right click and opt to open with a text editor. For the adotest.udl file, I have the following information, shown in the next paragraph. It's really very simple, especially when the authentication information is set for the Admin.
[oledb]
; Everything after this line is an OLE DB initstring
Provider=Microsoft.Jet.OLEDB.4.0;Data Source=C:\Program Files\
Microsoft Office\OFFICE11\SAMPLES\Northwind.mdb;
Persist Security Info=False
Create an MDB file, create a new form and add module
Just open your MS Access application and choose to Create a New File... which prompts you for a number of options. Choose to create a blank database. For this tutorial, I created an AdoTest.mdb file. I added a form and button with the caption Open/Close a database, as shown in the next picture. Since I do not need navigation and other related items, I chose not to show them by choosing property values for the items in the form's properties page. Instead of the Command button's click event, you may also use other events of other controls or even a Module.

Open the form in design view by first highlighting Form1 and then choosing Design View. Right click on the Command button, click on Build Event... and in the Choose Builder pop-up that comes up, click on Code Builder.

You will get to the screen shown next. If you want to go back to the form just click on the MS Access icon on the tool bar. In addition to Form1, I also have a Form2, which is not used in this tutorial. The code page for Form1 is called AdoTest - Form_Form1(code). This is where the code for the form and for any controls on the form are written. Presently there is no code except an empty click event for the Command0 button.

Next: Create a reference to ADO >>
More Microsoft Access Articles
More By Jayaram Krishnaswamy