BadgerLikeSpeed
Registered User.
- Local time
- Today, 08:35
- Joined
- Feb 7, 2013
- Messages
- 35
I have some code to look up the data from a previous week's entries to fill a form. It seems to work fine, unless the previous week crosses a month end. As in if the week runs from the 1/1/13 to 7/1/13 then then I go to the data entry form for the week starting 8/1/13 and everything is fine... But if the week runs from the 31/12/12 to the 6/1/13 then the dlookup code doesn't work.
The form asks for the starting date of the week, this is then taken to the table and the week ending date is calculated. Teh Dlookup code takes the week starting date and subtracts one day to get the previous week's ending date, and then looks up the data to fill in fields on the form. I hope that description makes sense...
Why would there be a difference when the week crosses a month end? It's not as though in the the example that the calculation crosses a month, as in 1/1/13 to 31/12/12, it's only 7/1/13 to 6/1/13. I had thought it was something to do with the year, but it also works accross months. As long as the whole week is in the same month then the code works. Any ideas?
The form asks for the starting date of the week, this is then taken to the table and the week ending date is calculated. Teh Dlookup code takes the week starting date and subtracts one day to get the previous week's ending date, and then looks up the data to fill in fields on the form. I hope that description makes sense...
Code:
Dim WkEnding As String
WkEnding = DateAdd("d", -1, [Forms]![TestEngDataNew]![WkSt])
GasOil = DLookup("[GOEnd]", "[WatEngDataWeek]", "[WkEnd] = #" & WkEnding & "#")
MELub = DLookup("[MELubEnd]", "[WatEngDataWeek]", "[WkEnd] = #" & WkEnding & "#")
AuxLub = DLookup("[AuxLubEnd]", "[WatEngDataWeek]", "[WkEnd] = #" & WkEnding & "#")
ZPellerLub = DLookup("[ZPelLubEnd]", "[WatEngDataWeek]", "[WkEnd] = #" & WkEnding & "#")
WinchLub = DLookup("[WinchLubEnd]", "[WatEngDataWeek]", "[WkEnd] = #" & WkEnding & "#")
PME = DLookup("[MEHPE]", "[WatEngDataWeek]", "[WkEnd] = #" & WkEnding & "#")
SME = DLookup("[MEHSE]", "[WatEngDataWeek]", "[WkEnd] = #" & WkEnding & "#")
GE1 = DLookup("[GE1E]", "[WatEngDataWeek]", "[WkEnd] = #" & WkEnding & "#")
GE2 = DLookup("[GE2E]", "[WatEngDataWeek]", "[WkEnd] = #" & WkEnding & "#")
GE3 = DLookup("[GE3E]", "[WatEngDataWeek]", "[WkEnd] = #" & WkEnding & "#")