Solved

about the query in ADO

Posted on 1998-06-01
6
163 Views
Last Modified: 2010-05-03
After creating a query, something like

Set OldDb = OpenDatabase("c;\file.mdb")
Set NewQry = OldDb.CreateQueryDef("Qry1")
NewQry.SQL = "select * from table1 where field1 like '*1*'"

How to access the selected records? Say debug.print first record.

Moreover, why not use

Set OldDb = OpenDatabase("c;\file.mdb")
Set NewSet = OldDb.OpenRecordset("select * from table1 where field1 like '*1*'")

which looks much easy and one may directely assess the selected records by the recordset.

0
Comment
Question by:victorlong
  • 4
  • 2
6 Comments
 
LVL 1

Accepted Solution

by:
Sekans earned 50 total points
ID: 1462254
victorlong,
To access the selected records, you would simply need to create a recordset, like this:

Set NewSet=OldDb.OpenRecordset("Qry1")

Then just move through the recordset:

NewSet.MoveFirst
Do Until NewSet.EOF = True
     'Do something
NewSet.MoveNext

Second question,
    I would indeed use the openrecordset with a SQL statement.

Regards,
Sekans
0
 
LVL 1

Expert Comment

by:Sekans
ID: 1462255
Sorry, I left the Loop off of the Do...Loop, it should look like this.

Do Until NewSet.EOF = True
     'Do something
      NewSet.MoveNext
Loop

Sekans
0
 

Author Comment

by:victorlong
ID: 1462256
Thank you Sekans. I want to make sure that

1. We can do:

   Set NewQry = OldDb.CreateQueryDef("Qry1")
   NewQry.SQL = "select * from table1 where field1 like '*1*'"
   Set NewSet = OldDb.OpenRecordset("Qry1")

2. The above is the same as:

   Qry2 = "select * from table1 where field1 like '*1*'"
   Set NewSet = OldDb.OpenRecordset(Qry2)

3. You like the second method.

0
How to run any project with ease

Manage projects of all sizes how you want. Great for personal to-do lists, project milestones, team priorities and launch plans.
- Combine task lists, docs, spreadsheets, and chat in one
- View and edit from mobile/offline
- Cut down on emails

 
LVL 1

Expert Comment

by:Sekans
ID: 1462257
1. Yes, this will create a new query object in the specified database, then return the records based on that query.

2. The two methods are almost the same.  The difference is, the first method actually creates a new query object in your database, while the second, only returns the desired records.  

3. Other experts may disagree, but I definately prefer the second method.  I don't see why you should junk up your database with queries, when you don't need to.  As you can see, the difference in code is minimal.

Hope this helps,
Sekans
0
 

Author Comment

by:victorlong
ID: 1462258
Hi Sekans

Thank you for your help.
0
 
LVL 1

Expert Comment

by:Sekans
ID: 1462259
Your very welcome,
Sekans
0

Featured Post

How to improve team productivity

Quip adds documents, spreadsheets, and tasklists to your Slack experience
- Elevate ideas to Quip docs
- Share Quip docs in Slack
- Get notified of changes to your docs
- Available on iOS/Android/Desktop/Web
- Online/Offline

Join & Write a Comment

Suggested Solutions

I’ve seen a number of people looking for examples of how to access web services from VB6.  I’ve been using a test harness I built in VB6 (using many resources I found online) that I use for small projects to work out how to communicate with web serv…
You can of course define an array to hold data that is of a particular type like an array of Strings to hold customer names or an array of Doubles to hold customer sales, but what do you do if you want to coordinate that data? This article describes…
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…
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…

762 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

18 Experts available now in Live!

Get 1:1 Help Now