General discussion

Locked

Access Database

By Tempest_Storm ·
How do i connect to an access database from VB6?

This conversation is currently closed to new comments.

5 total posts (Page 1 of 1)  
| Thread display: Collapse - | Expand +

All Comments

Collapse -

by willmarpo In reply to Access Database

There are several ways (ODBC, DAO, etc). The problem is that it depends on the Access version and VB6 service pack.
Which Access do you need to connect to?

Collapse -

by Tempest_Storm In reply to Access Database

It will be an access 2000 database i want to connect to. I am using VB Retail 6.0.8169 Version 8176.

If i create my database in access 2000 it will stay in that format wont it no matter what version the end user has?

Collapse -

by willmarpo In reply to

Ok, here is the first things to do:
1. Ensure you have the correct MDAC installed. Target the MDAC 2.8.
2. On VB6, at menu Project/References you must ensure the "Microsoft ActiveX Data Objects 2.8 Library" is selected.
3. You can either connect using a control or by code.
3a. Using a control, simply Ctrl-T and add a "Microsoft ADO Control". Just fill in the properties and you are connected!.
3b. Using Code, follow the lines:
Set ADOConn = New ADODB.Connection
ADOConn.Provider = "Microsoft.Jet.OLEDB.4.0"
ADOConn.ConnectionString = "Data Source=c:\PATH_TO_THE_DBFILE\DBFILE.mdb"
'If you need to provide a password, then
ADOConn.Properties("Jet OLEDB:Database Password") = "YOUR_PASSWORD"
ADOConn.Open

And you are set!

Good Luck....

Collapse -

by Tony Hopkinson In reply to Access Database

You use a TADOConnection component and set it's connectionstring property.
If you do it in designmode it gives you the option to build the connectionstring from a nice wizardly dialogue form'
After that you set and queries and commands connection prooperty to the adoconnection you created.
It's just a semicolon delimited string of name=values
'user=MyUser;Password=MyPassword;catalog= ....

Collapse -

by Miss Kitty In reply to Access Database

Here's a sample of code for you:
Dim objConn As New ADODB.Connection
Dim objCmd As New ADODB.Command
Dim objRS As New ADODB.Recordset
Dim objParam As ADODB.Parameter
Dim count As Integer

'set up the database pointer
objConn.Open "Provider=Microsoft.Jet.OLEDB.4.0;Persist Security Info=False;Data Source=E:\ACCESS\CONTRACT HAULERS\HAULER.mdb;User ID=ADMIN"
objRS.CursorType = adOpenDynamic
objRS.LockType = adLockOptimistic

'setting the Active Connection for the command object
objCmd.ActiveConnection = objConn

Good luck
Cathy

Back to Web Development Forum
5 total posts (Page 1 of 1)  

Related Discussions

Related Forums