Thomas45
asked on
accessing MSAccess 2000 from VB6
I now need to access MSAccess 2000 from VB6. Please can you let me know the procedure or point me in the right direction.
use ado
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.OL EDB.4.0;Pe rsist 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
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.OL
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
or Microsoft DAO
either will do. Just add the reference to the project (Project Menu, then References...)
Sombell
either will do. Just add the reference to the project (Project Menu, then References...)
Sombell
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.OL EDB.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, adLockOpti mistic
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.
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.OL
"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,
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.
ASKER CERTIFIED SOLUTION
membership
This solution is only available to members.
To access this solution, you must be a member of Experts Exchange.
oops, when I was looking at, no other comments, was there.
ASKER
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
msaccess2000 database.
Thanks