Link to home
Start Free TrialLog in
Avatar of parmarparveen
parmarparveen

asked on

How to store a query result in a variable?

Hi,

I have created a query which retuarns a single string value in result. I want to store this resulted string value in a variable for further comparison with other variables. Please help me with syntax.

Thanks
Praveen Parmar
ASKER CERTIFIED SOLUTION
Avatar of Patrick Matthews
Patrick Matthews
Flag of United States of America image

Link to home
membership
This solution is only available to members.
To access this solution, you must be a member of Experts Exchange.
Start Free Trial
SOLUTION
Link to home
membership
This solution is only available to members.
To access this solution, you must be a member of Experts Exchange.
Start Free Trial
Just an observation, Patrick, Joe.  Would this use less resources?

SomeString = CurrentDb.OpenRecordSet("qryName")!fldName

and is it as faster or slower than the DLookup()
Well, how about running a test in a loop of 100K times to see ?

mx

Did that already.  You lose by a factor of 2:1 ;-)
Cool.  That's a good trick!

What about MP's scheme, similar to yours but with the extra line of code.  Run that.

mx
SOLUTION
Link to home
membership
This solution is only available to members.
To access this solution, you must be a member of Experts Exchange.
Start Free Trial
Avatar of parmarparveen
parmarparveen

ASKER

Thanks
Public Function mCheckTime()
    Dim x As Long, n As Long, ID
    Dim ts
    x = 50000
    ts = Timer: For n = 1 To x: ID = DLookup("FIELD1", "query36"): Next n
    'ts = Timer: For n = 1 To x: ID = CurrentDb.OpenRecordset("query36")!FIELD1: Next n
    Debug.Print Timer - ts
End Function

DLookup:               71.59399
Open Recordset:   64.45398

mx
parmarparveen:  What didn't you like about the answer such that you rewarded a B with absolutely no feedback?  A  share would have been in order as both mx and mathewspatrick provided two ways of getting the variable, and I provided a variation on the theme, along with some test methodology and test results.  Mx went the extra mile and gave you his test methodology and results.  I am requesting you ask Community Support to re-open the question so it may be closed properly.  You should never close a question in that manner without giving the participants to correct any shortcoming you have observed.  
oops ... parmarparveen ... gRay meant that you should split the points between the 3 of us, and really gRay had the most efficient solution.  Can you once again Request Attention and fix this?

thx.mx
Thanks