DLookup Criteria 
Author Message
 DLookup Criteria

I am using the DLookup function to obtain a value from a
query and assign it to a variable in VBA.

I intend to run a loop so that each time I move through
the recordset, it will return the value of the current
record.

Example:

Do While ctr < 5
strprojno = DLookup("[ProjectNo]", "ProjectNosOnly")
DoCmd.GoToRecord acDataQuery, "ProjectNosOnly", acNext, 1
MsgBox strprojno
ctr = ctr + 1
Loop

This, as you can imagine, doesn't quite work, i.e. it
returns only the first value.  How would I be able to
obtain subsequent values from my query every time the code
loops?



Sat, 30 Apr 2005 17:21:41 GMT  
 DLookup Criteria
Vinay

I've looked over what you are doing, but still don't have a clear picture of
why...

Perhaps if you describe what you are trying to accomplish (rather than
how)...?

Good luck

Jeff Boyce
<Access MVP>



Sat, 30 Apr 2005 21:11:38 GMT  
 DLookup Criteria
U need 2 use a record set in DAO or ADO to loop thru the
recordset. perform your operation inside the loop so the
the variable set can retain the info until it move to the
next record.

Quote:
>-----Original Message-----
>I am using the DLookup function to obtain a value from a
>query and assign it to a variable in VBA.

>I intend to run a loop so that each time I move through
>the recordset, it will return the value of the current
>record.

>Example:

>Do While ctr < 5
>strprojno = DLookup("[ProjectNo]", "ProjectNosOnly")
>DoCmd.GoToRecord acDataQuery, "ProjectNosOnly", acNext, 1
>MsgBox strprojno
>ctr = ctr + 1
>Loop

>This, as you can imagine, doesn't quite work, i.e. it
>returns only the first value.  How would I be able to
>obtain subsequent values from my query every time the
code
>loops?
>.



Sun, 01 May 2005 02:42:24 GMT  
 
 [ 3 post ] 

 Relevant Pages 

1. Dlookup Criteria Problem

2. DLookup function used as criteria in query

3. DLookup with multiple criteria A97

4. Multiple Numeric Criteria in a DLookup Function

5. dlookup and date field criteria

6. AppointmentItem.Items.Find (criteria) - how to specify Start and End criteria

7. DLookup in report not working

8. DLookup problem

9. DLookup usage help

10. DLookup

11. DLookup

12. dlookup

 

 
Powered by phpBB® Forum Software