Created a Temporary Query in Memory VBA

L

LA Lawyer

In Access 2007, I want to create a "temporary query" in memory only so that
I can extract the ItemNo of each (or the first) record which meets certain
criteria.

How is that done?
 
A

Albert D. Kallal

LA Lawyer said:
In Access 2007, I want to create a "temporary query" in memory only so
that I can extract the ItemNo of each (or the first) record which meets
certain criteria.

How is that done?

You don't mention what you want to do with that data once you pulled it into
some "memory" structure.

The general approach is to use what we call a record-set.

For example, to pull all customer records that belong to my city, the code
would look like:


dim rstData as dao.RecordSet

set rstData = currentdb.
OpenreocrdSet("select * from tblCustomers where city =
'Edmonton'")

The real question is now that you pulled the records into rstData, what do
you want to do?

You could process all of the records like:

do while rstData.EOF = false
debug.Print rstData!AmountOwe
rstData.MoveNext
loop

rstData.Close

It just not quite clear what you want to do here. The above would return all
collums of each record. If you just wanted the "id", then you could go:


set rstData = currentdb.
OpenreocrdSet("select id from tblCustomers where city =
'Edmonton'")

Also, the above is on one line...this newsreader might be wrapping this a
bit....
 

Ask a Question

Want to reply to this thread or ask your own question?

You'll need to choose a username for the site, which only take a couple of moments. After that, you can post your question and our members will help you out.

Ask a Question

Top