Solved

executing an access query from VB6 app

Posted on 2003-11-03
4
422 Views
Last Modified: 2010-05-01
i want to connect to an access db then execute one of its querys.

I want to do this from a seperate vb6 application.

some code would be great

thanks
0
Comment
Question by:MrKevorkian
[X]
Welcome to Experts Exchange

Add your voice to the tech community where 5M+ people just like you are talking about what matters.

  • Help others & share knowledge
  • Earn cash & points
  • Learn & ask questions
  • 2
4 Comments
 
LVL 1

Author Comment

by:MrKevorkian
ID: 9669954
ps the query is in an access 2000 db
0
 
LVL 53

Accepted Solution

by:
Dhaest earned 150 total points
ID: 9669981
1) make sure that you have the libraries included in your project

under vb6 go to tools -> reference -> add ms ado 2.5 (or higher) and ms vb for applications extensibility

2) create the database object and recordset object

Dim conn As New ADODB.Connection
Dim rcd As New ADODB.Recordset

3) open the connection

conn.ConnectionString = "Provider=Microsoft.JET.OLEDB.4.0;Data Source=D:\path\file.mdb;"
conn.Open()

4) execute the query
rcd.execute ("YourQueryName")

 
For more information about ADO:

http://www.w3schools.com/ado/
http://www.tutorial-web.com/asp/database/
http://www.devguru.com/features/tutorials/ADOandASP/adoTutorial.html 
0
 
LVL 13

Expert Comment

by:VICKRAM
ID: 9670000
here it is
make a reference to ActiveX Data Objects Library..i used ADO 2.1

Dim adoCon As New ADODB.Connection
Dim adoCom As New ADODB.Command
   
Dim adoRs As ADODB.Recordset
   
adoCon.Open "Provider=Microsoft.Jet.OLEDB.4.0;Data Source=C:\data.mdb;Persist Security Info=False"

adoCom.CommandType = adCmdStoredProc
adoCom.CommandText = "qryQueryName"
adoCom.ActiveConnection = adoCon
   
Set adoRs = adoCom.Execute()

While Not adoRs.Eof
   ' DO YOUR PROCESSING HERE
Wend

vickram
0
 
LVL 1

Author Comment

by:MrKevorkian
ID: 9670038
both were correct but  Dhaest was first

thanks very much
0

Featured Post

Creating Instructional Tutorials  

For Any Use & On Any Platform

Contextual Guidance at the moment of need helps your employees/users adopt software o& achieve even the most complex tasks instantly. Boost knowledge retention, software adoption & employee engagement with easy solution.

Question has a verified solution.

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

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…
This article describes how to use a set of graphical playing cards to create a Draw Poker game in Excel or VB6.
Get people started with the process of using Access VBA to control Excel using automation, Microsoft Access can control other applications. An example is the ability to programmatically talk to Excel. Using automation, an Access application can laun…
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…
Suggested Courses
Course of the Month10 days, 13 hours left to enroll

628 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