Solved

accessing MSAccess 2000 from VB6

Posted on 2001-06-15
7
247 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
6 Surprising Benefits of Threat Intelligence

All sorts of threat intelligence is available on the web. Intelligence you can learn from, and use to anticipate and prepare for future attacks.

 
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

Why You Should Analyze Threat Actor TTPs

After years of analyzing threat actor behavior, it’s become clear that at any given time there are specific tactics, techniques, and procedures (TTPs) that are particularly prevalent. By analyzing and understanding these TTPs, you can dramatically enhance your security program.

Join & Write a Comment

Enums (shorthand for ‘enumerations’) are not often used by programmers but they can be quite valuable when they are.  What are they? An Enum is just a type of variable like a string or an Integer, but in this case one that you create that contains…
Since upgrading to Office 2013 or higher installing the Smart Indenter addin will fail. This article will explain how to install it so it will work regardless of the Office version installed.
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…
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…

706 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

Need Help in Real-Time?

Connect with top rated Experts

22 Experts available now in Live!

Get 1:1 Help Now