TblTimings houses the data regarding the go live dates and task values.
tblData has the entry date, and it is currently set up to be pulled into the query that this function would be plugged into.
i.e. taskID 2 had a value of 2.0 beginning on 1/1/10, the value was updated on 6/1/10 to be 30.0
Now the people using the database enter their info for entry date on 4/1/10.
I want the function to match 4/1/10 to see that taskID 2 had a value of 2.0 on 4/1/10.
I was trying to get it to review DateDiff that was the smallest value without being less than zero.
I am pretty new to coding, so I was wondering if someone could take a look and let me know what they think...
Thanks
D
Expand|Select|Wrap|Line Numbers
- Function GetTiming(EntryDate, TaskID) As Double
- Dim sqlstr As String
- Dim db As Database
- Dim rs As Recordset
- sqlstr = "SELECT tblTimes.TimingID, tblTimes.TaskID, tblTimes.LiveDate, tblTimes.Timing FROM tblTimes WHERE (((tblTimes.TaskID) = " & TaskID & "))ORDER BY tblTimes.LiveDate DESC;"
- Set db = CurrentDb
- Set rs = db.OpenRecordset(sqlstr)
- If rs.RecordCount = 0 Then
- GetTiming = 0
- 'MsgBox "No records found"
- Exit Function
- End If
- If rs.RecordCount = 1 Then
- GetTiming = rs!Timing.Value
- Exit Function
- End If
- Do Until Not rs.EOF
- Debug.Print TaskID & ": " & rs!Timing.Value
- If DateDiff("d", EntryDate, rs!LiveDate.Value) >= 0 Then GetTiming = rs!Timing.Value: Exit Do
- rs.MoveNext
- Loop
- rs.Close
- End Function
Access 2003, sorry I forgot that. This is my first question on the boards. Newbie. :)