Query output in a parameter

khurram7x

Registered User.
Local time
Tomorrow, 04:00
Joined
Mar 4, 2015
Messages
226
How could i get output of a Query in a VBA variable please?? i'm trying as below but i'm getting error:

Dim output As Integer
vari = DoCmd.OpenQuery("qryCompare", acViewNormal, acReadOnly)

Output of a query is a single MAX value.

Thanks.
 
Hi,

There are a few ways:
1 - if all you need is one value, use DLookup function: http://www.techonthenet.com/access/functions/domain/dlookup.php.
For output of a set of data, look into (that is, google) Recordset. In Access, I find Dao.Recorset to be quite simple and fine to use.
try this: http://www.everythingaccess.com/tutorials.asp?ID=VBA-Traps:-Working-with-Recordsets
or this: https://msdn.microsoft.com/en-us/library/office/ff820966.aspx

If you want to stick to the trivial, go with Dlookup.

ATB
 
Since you are looking for the Max value consider whether the DMax function might do the job. It is quite similar to DLookup but returns the Max value.
 
Thanks Glaxiom, DLookUp solved my immediate problem.

Marlan, thank you for RecordSet references. Next chapter in my VBA is on SQL and i've seen RecordSet discussed there. I've quickly seen your references and they're packed with valuable information. I'll get back on them once I go through my next VBA lesson.
 

Users who are viewing this thread

Back
Top Bottom