VBA Query --Help Me Pl

gdanalakshmi

Registered User.
Local time
Today, 02:51
Joined
Nov 26, 2002
Messages
102
I want to run a query in VBA and I know the query will always return only 1 record.
I need the fields in the result record for further processing.

If I run like this DoCMd.OpenQuery "QryNAme" the query runs , but how do I capture the result for furtehr manipulation.
 
You can use the DLookup() function to return the value from the query:-

DLookup("FieldName","QryName")
 
Under Access Help, look up RecordSets. Or, if you are looking for only 1 field,DLookup works nicely.

Dim dbs as Database
Dim rst as RecordSet

Set dbs = CurrentDB
Set rst = dbs.OpenRecordSet("QryNAme")

Then you can reference your field by:
rst!MyField
 

Users who are viewing this thread

Back
Top Bottom