Solved

about the query in ADO

Posted on 1998-06-01
6
167 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
Free Tool: SSL Checker

Scans your site and returns information about your SSL implementation and certificate. Helpful for debugging and validating your SSL configuration.

One of a set of tools we are providing to everyone as a way of saying thank you for being a part of the community.

 
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

Free Tool: ZipGrep

ZipGrep is a utility that can list and search zip (.war, .ear, .jar, etc) archives for text patterns, without the need to extract the archive's contents.

One of a set of tools we're offering as a way to say thank you for being a part of the community.

Question has a verified solution.

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

Suggested Solutions

Title # Comments Views Activity
VBA/SQL - Connect to SQL server and pull data 4 118
vb6 connector to SQL Server 2 37
Can we place a tooltip on the actual vb6 form 5 48
transition to visual .net from vb6 5 37
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…
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…
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…
Get people started with the utilization of class modules. Class modules can be a powerful tool in Microsoft Access. They allow you to create self-contained objects that encapsulate functionality. They can easily hide the complexity of a process from…

840 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