how to call a pre-defined query

jamest85

Registered User.
Local time
Today, 05:10
Joined
Jan 20, 2008
Messages
52
Hi;

I have created query: qryNumProudcts. It works fine.

Now I want to call this query, what is the syntax for this, by the way, since the query will return a number, how can I get this value, also, do I need create action query?

Thank you very much,

JT
 
What do you mean by call the query

If possible give the field names and tell me what data is in there and what data you want to get

Regards

Khawar
 
What do you mean by call the query

If possible give the field names and tell me what data is in there and what data you want to get

Regards

Khawar

Hi: Khawar

1. in the Objects window -> Queries -> Create New Query

2. The "Simple Query Wizard" will ask me which table, I selete tblProducts.

3. in the query build window: Field1: totalCount: Count(*), Field 2: productsId. (hide this field)

4. So I will get the total number of products. the query name is: qryTotalProducts

5. Now, from my Moudle, I want to use VBA code to call above query, and the the returned total number.

Something like this below? But how can I get the return value?
DoCmd.SetWarnings False
CurrentDb.Execute qryTotalProducts
DoCmd.SetWarnings True


Thanks
 
Actually you don't need the query at all:

DCount("*", "tblProducts")

should return the number of records in that table.
 
I still want to call the query

Actually you don't need the query at all:

DCount("*", "tblProducts")

should return the number of records in that table.

Thanks for your hlep.
In fact the query is pretty complicated(the query is calling another query...), the example I put is just simplified.
So I still want to call the query, and get the query retrun values.
How to do that?
Thanks.
 
Either open a recordset on it or:

DLookup("FieldName", "qryTotalProducts")
 
Either open a recordset on it or:

DLookup("FieldName", "qryTotalProducts")

can i write this:
Dim iCount As Integer

iCount = DLookup("FieldName", "qryTotalProducts")

So the "iCount" will have the value of "FiledName" which cotains the totalNumofProducts?

Thanks.
 
That looks like it should work. Seems simple enough to test.
 

Users who are viewing this thread

Back
Top Bottom