Dlookup Issue with multiple criteria

foxhound

Board Regular
Joined
Mar 21, 2003
Messages
182
Hello,

I am using Access 2000 and have searched everywhere and cannot find the answer to this! I want to lookup [hours] (a number field) in a table where [group] can be a dynamic group name and, [low_months] and [high_months] are number fields. If my value, yrssrv is between [low_months] and [high_months] and my value, grp matches [group] then I need to know the number of [hours] in [tbl_Vacation Schedule (New Prior Year)].

...something like this but using between.

numhours = DLookup("[Hours]", "[tbl_Vacation Schedule (New Prior Year)]", _
"[group]= '" & grp & "'" & _
" And [Low_Months] >= " & yrssrv & _
" And [High_Months] <= '" & yrssrv & "'")
 

Excel Facts

Links? Where??
If Excel says you have links but you can't find them, go to Formulas, Name Manager. Look for old links to dead workbooks & delete.
Thanks for the suggestion Norie :-D I tried almost every combination I could to use "between" and couldn't get it to work. Here is my latest attempt that still doesn't work:

rs_Snapshot!VacAwardHours = DLookup("[Hours]", "[tbl_Vacation Schedule (New Prior Year)]", _
"[group]= '" & VGF & "'" And " & yrssrv & "" between LOW_" & CalcMethod & " and HIGH_" & CalcMethod)

"VGF" is a text field
"yrssrv" is a number field
"CalcMethod" is a text variable that I use to switch between "months" and "years"
 
Upvote 0
Here is sql code that works when returning the record in a recordset but I need to use dlookup() instead :-D

"Select [HOURS] from " & VacSchedule & " where [GROUP] = '" & VGF & "'" _
& " and (" & srvyrs & " BETWEEN LOW_" & CalcMethod & " and HIGH_" & CalcMethod & ")"
 
Upvote 0
When you run that SQL code are you prompted for parameters?
 
Upvote 0
I had the parameters defined already so I didn't get an error on the sql. Guess what? I finally tinkered with the code enough and got this to work!


rs_Snapshot!VacAwardHours = DLookup("[Hours]", VacSchedule, _
"[group]= '" & VGF & "'" & _
" And (" & int_Years & " between [Low_" _
& CalcMethod & "] And [High_" & CalcMethod & "])")


Norie, thanks for your assistance. Now I just need to get the other post resolved :-D
 
Upvote 0

Forum statistics

Threads
1,223,275
Messages
6,171,119
Members
452,381
Latest member
Nova88

We've detected that you are using an adblocker.

We have a great community of people providing Excel help here, but the hosting costs are enormous. You can help keep this site running by allowing ads on MrExcel.com.
Allow Ads at MrExcel

Which adblocker are you using?

Disable AdBlock

Follow these easy steps to disable AdBlock

1)Click on the icon in the browser’s toolbar.
2)Click on the icon in the browser’s toolbar.
2)Click on the "Pause on this site" option.
Go back

Disable AdBlock Plus

Follow these easy steps to disable AdBlock Plus

1)Click on the icon in the browser’s toolbar.
2)Click on the toggle to disable it for "mrexcel.com".
Go back

Disable uBlock Origin

Follow these easy steps to disable uBlock Origin

1)Click on the icon in the browser’s toolbar.
2)Click on the "Power" button.
3)Click on the "Refresh" button.
Go back

Disable uBlock

Follow these easy steps to disable uBlock

1)Click on the icon in the browser’s toolbar.
2)Click on the "Power" button.
3)Click on the "Refresh" button.
Go back
Back
Top