In this tutorial, I will show you how to connect Visual Basic 6 to Microsoft Access using ADODC control.
Here our database will contain three data fields. Name, Number and City and our VB6 project will contain three TextBoxes to display the data.
Our final project will look like this:
Step 2: Select Standard EXE and OPEN
Step 4: In the components window, under controls tab find “Microsoft ADO Data Control 6.0 (OLEDB)” and select and tick the box, click Apply then OK.
After clicking “OK” the ADODC tool will be added to your VB6 ToolBox
We are using Microsoft Access 2013 for our database.
Step 5: Open Microsoft Access 2013 — select blank desktop — name your database whatever you want — click Create
Note: Always save your database as .mdb (2002 – 2003 file format) whenever you are working with VB6
Step 6: Go to Create tab and select Table Design
Here I am adding three fields “Name” , “Number” and “City”.
Step 8: Select File and Save. A “Save as” window will pop up — click Ok.
Step 9: Double click on table name and enter the data. (Later we will add data from VB6)
After adding data save the file and exit.
Now we will connect this table to our VB6 ADODC control
Step 10: Select the ADODC control (which you have already created on the VB6 form ) and from the properties window, select ConnectionString
Step 11: The Property page window will open. Select Build
Step 12: After clicking Build, the Data Link Properties window will open.
Now under Provider tab select Microsoft Jet 4.0 OLE DB Provider and click on Next
Step 13: Under Connection tab browse and select your database file (.mdb) and click Ok
You have successfully connected your database file with VB6 ADODC control.
Step 14: Again select the ADODC control and from the properties window, select RecordSource
Step 15: On the “Property pages” window, select Command Type (2- ad CmdTable) and Table or Stored Procedure Name (See the below image)
Now that everything related to connection is complete, we have to display the contents of the database file.
Step 16: Here I am creating three TextBoxes and three labels
Step 17:Select a TextBox and select DataSource and then DataField.
Now click Start and see the final result.