Still celebrating National IT Professionals Day with 3 months of free Premium Membership. Use Code ITDAY17

x
?
Solved

about the query in ADO

Posted on 1998-06-01
6
Medium Priority
?
178 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
[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
  • 4
  • 2
6 Comments
 
LVL 1

Accepted Solution

by:
Sekans earned 200 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
Industry Leaders: We Want Your Opinion!

We value your feedback.

Take our survey and automatically be enter to win anyone of the following:
Yeti Cooler, Amazon eGift Card, and Movie eGift Card!

 
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

Concerto Cloud for Software Providers & ISVs

Can Concerto Cloud Services help you focus on evolving your application offerings, while delivering the best cloud experience to your customers? From DevOps to revenue models and customer support, the answer is yes!

Learn how Concerto can help you.

Question has a verified solution.

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

Have you ever wanted to restrict the users input in a textbox to numbers, and while doing that make sure that they can't 'cheat' by pasting in non-numeric text? Of course you can do that with code you write yourself but it's tedious and error-prone …
Most everyone who has done any programming in VB6 knows that you can do something in code like Debug.Print MyVar and that when the program runs from the IDE, the value of MyVar will be displayed in the Immediate Window. Less well known is Debug.Asse…
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…
Suggested Courses

722 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