Tek-Tips is the largest IT community on the Internet today!

Members share and learn making Tek-Tips Forums the best source of peer-reviewed technical information on the Internet!

  • Congratulations SkipVought on being selected by the Tek-Tips community for having the most helpful posts in the forums last week. Way to Go!

Referencing a query in code 1

Status
Not open for further replies.

TheComputerDude

Programmer
Feb 27, 2006
14
0
0
US
I prefer to write my queries in code, but I am not sure how to reference them from another query. I know FoxPro supports cursors, but Is this possible in Access?
 
As Jerry said ... but with a bit of elaboration ...

Just writing and running some SQL in code doesn't make it a "query" in the Access sense. To make it something that you can reference in another query you must append it to Access's QueryDefs collection. Something like this
Code:
Dim SQL As String
SQL = "Select * From TheTable Where fld1 < 99"
CurrentDb.CreateQueryDef("myQuery", SQL)
Then you can refer to "myQuery" in other queries just as you would a table.

The above example is DAO and there are equivalent mechanisms in ADO. There you will append the query to an ADOX Catalog.
 
Status
Not open for further replies.

Part and Inventory Search

Sponsor

Back
Top