Solved

tutorial on how to connect Access Database using VB6

Posted on 2010-09-11
7
332 Views
Last Modified: 2013-12-25
How to connect Access Database 2003 using VB6 without ADO Data Control.
How to Add, edit, delete, retreive.
0
Comment
Question by:PagodNaUtak
  • 4
  • 2
7 Comments
 
LVL 4

Accepted Solution

by:
antonybrahin earned 500 total points
ID: 33655728

'in general section
dim conn as adodb.connection
dim rs as adodb.recordset

'in form load
set conn=new adodb.connection
set rs=new adodb.recordset

conn="provider=microsoft jet.4.0.oledb;data source=<ur database name>;persist security info=false"
conn.open
rs.open "select *from ur tablename",conn,adopendynamic,adlockoptimistic

Open in new window

0
 
LVL 65

Expert Comment

by:rockiroads
ID: 33655732
there is dao. add a reference to microsoft dao library, pick the latest one

to connect to the database, define a dao.database variable and use opendatabase
eg

dim db as dao.database

set db = dao.opendatabase("c:\mydb.mdb")


to close do this

db.close
set db = nothing

to define recordsets you use the db object
eg

dim rs as dao.recordset

set rs= db.openrecordset("select * from mytable")

to close

rs.close
set rs=nothing


the above shows how to select a record, then you iterate using this

dp while rs.eof = false

    'reference your field
    rs!myfield

    'next record
    rs.movenext
loop
0
 
LVL 4

Expert Comment

by:antonybrahin
ID: 33655736
sorry abt the previous post..

refer this for ADO DC.

http://www.vb6.us/tutorials/database-access-ado-vb6-tutorial
0
How your wiki can always stay up-to-date

Quip doubles as a “living” wiki and a project management tool that evolves with your organization. As you finish projects in Quip, the work remains, easily accessible to all team members, new and old.
- Increase transparency
- Onboard new hires faster
- Access from mobile/offline

 
LVL 6

Expert Comment

by:judgeking
ID: 33655738
Excellent ADO tutorial here:http://www.w3schools.com/ado/default.asp

You don't need to use the ADO Data Control, just the ADO libraries.

Connect is simple:
  Dim  Conn As New ADODB.Connection
  Conn.Provider="Microsoft.Jet.OLEDB.4.0"
  Conn.Open "c:/webdata/northwind.mdb"

Open Recordset/Retrieve:
    Rs.Open "Select * from Customers", Conn, adOpenDynamic, adLockBatchOptimistic
   iCompanyID = Rs.fields("CompanyID")
   Rs.MoveNext
   'etc

Add:
  Rs.AddNew
  Rs.fields("CompanyID") = 1
  Rs.fields("Active") = True
  Rs.UpdateBatch

Delete:
  'Either:
  Conn.Execute "DELETE From Customers WHERE Active=0"
  'Or
  Rs.Find "CustomerID = 99"
  If Not Rs.EOF Then Rs.Delete
 
   

Add:
0
 
LVL 65

Expert Comment

by:rockiroads
ID: 33655739
to add a record you can do it one of two ways

using your recordset

rs.addnew
rs!field1 = somevalue
rs!field2 = somevalue
rs.update

or create a string with your sql and do this

db.execute "sql string"


to delete you can use db.execute

or from the recordset  rs.delete

0
 
LVL 65

Expert Comment

by:rockiroads
ID: 33655743
some more info on dao  http://articles.techrepublic.com.com/5100-10878_11-1045296.html


now you said without using ado, dao is the one thing I can think off. I remember using something called RDO which was oracle's ado equivalent or something but can't think of any other alternatives.
0
 
LVL 65

Expert Comment

by:rockiroads
ID: 33776228
Just curious why you accepted ADO when you said you didn't want ADO control. Its not about points but rather your question.
0

Featured Post

What Security Threats Are You Missing?

Enhance your security with threat intelligence from the web. Get trending threat insights on hackers, exploits, and suspicious IP addresses delivered to your inbox with our free Cyber Daily.

Join & Write a Comment

When trying to find the cause of a problem in VBA or VB6 it's often valuable to know what procedures were executed prior to the error. You can use the Call Stack for that but it is often inadequate because it may show procedures you aren't intereste…
If you have ever used Microsoft Word then you know that it has a good spell checker and it may have occurred to you that the ability to check spelling might be a nice piece of functionality to add to certain applications of yours. Well the code that…
Show developers how to use a criteria form to limit the data that appears on an Access report. It is a common requirement that users can specify the criteria for a report at runtime. The easiest way to accomplish this is using a criteria form that a…
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…

705 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

12 Experts available now in Live!

Get 1:1 Help Now