Solved

accessing MSAccess 2000 from VB6

Posted on 2001-06-15
7
251 Views
Last Modified: 2010-05-02
I now need to access  MSAccess 2000 from VB6. Please can you let me know the procedure or point me in the right direction.
0
Comment
Question by:Thomas45
7 Comments
 
LVL 18

Expert Comment

by:deighton
ID: 6194813
use ado
0
 
LVL 1

Expert Comment

by:BartonM
ID: 6194826
Hi Thomas,

To access an MSAccess database you can use an ADO connection. First you have to enable ADO by selecting the ActiveX Data Objects type library in Project->References.

If you want to access the data in code only, you can use the following code to make a connection:

dim cn as ADODB.Connection
dim rs as ADODB.Recordset

Set cn = New ADODB.Connection

cn.Open "Provider=Microsoft.Jet.OLEDB.4.0;Persist Security Info=False;Data Source = C:\database.mdb"

set rs = new ADODB.Recordset
rs.Open "SELECT * FROM Table1", cn


Another way is to add the ADO Data Control (adodc) to a form. With this control you can also connect to a database.

BartonM
0
 
LVL 3

Expert Comment

by:sombell
ID: 6194828
or Microsoft DAO

either will do. Just add the reference to the project (Project Menu, then References...)

Sombell
0
Technology Partners: We Want Your Opinion!

We value your feedback.

Take our survey and automatically be enter to win anyone of the following:
Yeti Cooler, Amazon eGift Card, and Movie eGift Card!

 
LVL 9

Expert Comment

by:Valliappan AN
ID: 6194851
You need to learn the usage of how to open a Connection, a recordset, execute a query, retrieve data using recordset, save data using recordset. Learn about ADO, you could start from: http://www.microsoft.com/data/ado/default.htm

ok, to just give some idea on how to do it:

You need to set Project/References in VB to : Microsoft ActiveX Data Objects 2.5 (or later), that you have in your m/c.

To open a connection to Access do like this:

Dim Conn1 As ADODB.Connection
Conn1.Open "Provider=Microsoft.Jet.OLEDB.4.0;" & _
                   "Data Source=\pathname\Db1.mdb;" & _
                   "User Id=admin;" & _
                   "Password=;"

To open a recordset (a set of records):

Dim rs1 As Recordset

Set rs1=New Recordset
rs1.Open "Select * FROM able1",Conn1,adOpenKeySet,adLockOptimistic

To get data from recordset:

Text1.Text = rs1("field1name").Value

To add data to table:

rs1.AddNew
rs1("field1")=Value1
rs1("field2")=Value2
:
rs1.Update

To edit data, you could locate the record, using FIND method, and then do as above, but without AddNew statement.

To delete data, you could locate the record, and do,
rs1.Delete

Thats it. I am not sure, this is what you wanted.

If not, please, ignore this, and explain, what you wanted.
Thank you.

Cheers.

0
 
LVL 43

Accepted Solution

by:
TimCottee earned 100 total points
ID: 6194853
But make sure that if you are using ADO that you have at least version 2.1 or higher version 2.0 does not allow use of MS access 2000 databases. If you are using DAO you also need to make sure that your project references are for DAO 3.6 rather than 3.5 as the older versions are not compatible with access 2000. YOu can download the latest versions of MDAC from http://www.microsoft.com/data I would recommend v2.51 as v2.6 does not include all the jet drivers. These are available seperately from http://www.microsoft.com/data/download_Jet4sp3.htm

If you are using VB6 SP4 then you will already have at least MDAC 2.5 installed and should be able to select the appropriate references without any extra downloads.
0
 
LVL 9

Expert Comment

by:Valliappan AN
ID: 6194862
oops, when I was looking at, no other comments, was there.
0
 

Author Comment

by:Thomas45
ID: 6206438
I need the DAO 3.6, thats it, I am updating from 2.5/3.5 and was not sure what I need to access
msaccess2000 database.

Thanks
0

Featured Post

Independent Software Vendors: We Want Your Opinion

We value your feedback.

Take our survey and automatically be enter to win anyone of the following:
Yeti Cooler, Amazon eGift Card, and Movie eGift Card!

Question has a verified solution.

If you are experiencing a similar issue, please ask a related question

Suggested Solutions

Title # Comments Views Activity
VBA to copy paste columns form one file to other 20 100
VBA error replacing data 6 41
Run code from text file in vb 1 84
Excel Automation VBA 19 101
Have you ever wanted to restrict the users input in a textbox to numbers, and while doing that make sure that they can't 'cheat' by pasting in non-numeric text? Of course you can do that with code you write yourself but it's tedious and error-prone …
If you need to start windows update installation remotely or as a scheduled task you will find this very helpful.
Get people started with the utilization of class modules. Class modules can be a powerful tool in Microsoft Access. They allow you to create self-contained objects that encapsulate functionality. They can easily hide the complexity of a process from…
This lesson covers basic error handling code in Microsoft Excel using VBA. This is the first lesson in a 3-part series that uses code to loop through an Excel spreadsheet in VBA and then fix errors, taking advantage of error handling code. This l…

679 members asked questions and received personalized solutions in the past 7 days.

Join the community of 500,000 technology professionals and ask your questions.

Join & Ask a Question