Go Premium for a chance to win a PS4. Enter to Win

x
?
Solved

accessing MSAccess 2000 from VB6

Posted on 2001-06-15
7
Medium Priority
?
261 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
Concerto Cloud for Software Providers & ISVs

Can Concerto Cloud Services help you focus on evolving your application offerings, while delivering the best cloud experience to your customers? From DevOps to revenue models and customer support, the answer is yes!

Learn how Concerto can help you.

 
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 300 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

How to Use the Help Bell

Need to boost the visibility of your question for solutions? Use the Experts Exchange Help Bell to confirm priority levels and contact subject-matter experts for question attention.  Check out this how-to article for more information.

Question has a verified solution.

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

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 …
Background What I'm presenting in this article is the result of 2 conditions in my work area: We have a SQL Server production environment but no development or test environment; andWe have an MS Access front end using tables in SQL Server but we a…
As developers, we are not limited to the functions provided by the VBA language. In addition, we can call the functions that are part of the Windows operating system. These functions are part of the Windows API (Application Programming Interface). U…
Get people started with the process of using Access VBA to control Outlook using automation, Microsoft Access can control other applications. An example is the ability to programmatically talk to Microsoft Outlook. Using automation, an Access applic…
Suggested Courses
Course of the Month12 days, 23 hours left to enroll

972 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