Tek-Tips is the largest IT community on the Internet today!

Members share and learn making Tek-Tips Forums the best source of peer-reviewed technical information on the Internet!

  • Congratulations Westi on being selected by the Tek-Tips community for having the most helpful posts in the forums last week. Way to Go!

looking up values in a different query

Status
Not open for further replies.

grgimpy

Programmer
Nov 1, 2006
124
US
My form (SM Developer-ShiftlyPM) has a record source (SM Developer-Shiftly PM Log Query) which is a query. I want to look up a value from a different query (SM Developer-pH Chart Query) to calculate the value for SMD-pHMovingRange below. How can I change the DoCmd code to go to the last record in a different query?

Dim a, b As Variant
DoCmd.GoToRecord , , acLast
a = DLookup("[SMD-pH Lab]", "SM Developer-pH Chart Query")
DoCmd.GoToRecord , , acPrevious
b = DLookup("[SMD-pH Lab]", "SM Developer-pH Chart Query")
Me.SMD_pHMovingRange = Abs(b - a)
 
i'm asking the wrong question here. i just realized the DLookup command looks up the same value regardless of what I put in front of it. There is a timestamp on each of my records. How would I write a DMax specifically to look up the entry with the most recent time? Then, I need to also look up the entry with the second most recent time, which I also need help with.

Thanks.
 
Something like this ?
t = DMax("[TimeStamp field]", "SM Developer-pH Chart Query")
a = DLookup("[SMD-pH Lab]", "SM Developer-pH Chart Query", "[TimeStamp field]=#" & t & "#")
t = DMax("[TimeStamp field]", "SM Developer-pH Chart Query", "[TimeStamp field]<#" & t & "#")
b = DLookup("[SMD-pH Lab]", "SM Developer-pH Chart Query", "[TimeStamp field]=#" & t & "#")

Hope This Helps, PH.
Want to get great answers to your Tek-Tips questions? Have a look at FAQ219-2884 or FAQ181-2886
 
Status
Not open for further replies.

Part and Inventory Search

Sponsor

Back
Top