This is my code. I am using this function to in a datediff calculation.
Public Function GatherKeyDates(ByVal sRDNumber, ByVal strField, ByVal
lKeyDateID) As Date
On Error GoTo Err_GatherKeyDates
Dim dtResult As Date, sSQL As String
Dim MyRS As ADODB.Recordset
Dim sResult As String
sSQL = "Select tbl_RD_KeyDates." & strField
sSQL = sSQL & " FROM tbl_RD_KeyDates "
sSQL = sSQL & "WHERE (((tbl_RD_KeyDates.RD_Number)= '" & sRDNumber & "')
AND ((tbl_RD_KeyDates.KeyDateTypeID)= " & lKeyDateID & " ) AND
((tbl_RD_KeyDates." & strField & " ) Is Not Null));"
Set MyRS = New ADODB.Recordset
With MyRS
.CursorLocation = adUseClient
.Open Source:=sSQL, ActiveConnection:=CurrentProject.Connection
If .RecordCount Then
dtResult = Nz(.Fields(strField).Value, 0)
End If
.Close
End With
Exit_GatherKeyDates:
Set MyRS = Nothing
GatherKeyDates = dtResult
Exit Function
Err_GatherKeyDates:
Call ErrHandler("GatherKeyDates function", Err.Number, Err.Description)
Resume Exit_GatherKeyDates
End Function