This gets the date from a table record
''''''''''''''''''''''''''
Function GetMonthTDL()
Dim db As Database
Dim rstPathTDL As DAO.Recordset
Set db = CurrentDb
Dim PathTDLDate As Date
On Error GoTo err_norec
Set rstPathTDL = db.OpenRecordset("Pathdata_TDL", dbOpenSnapshot) 'query with records to be aded
rstPathTDL.MoveFirst
PathTDLDate = rstPathTDL("Date_Tdl")
rstPathTDL.Close
Set db = Nothing
GetMonthTDL = PathTDLDate
Exit Function
err_norec:
Exit Function
End Function
''''''''''''''''''''''''''''''''''
I then get the first of the month.
''''''''''''''''''''''''''''''''''
datDate = GetMonthTDL
datDate = DateSerial(Year(datDate), Month(datDate), 1)
'''''''''''''''''''''''''''''''''''''''''''''''''
and put it into the sql
'''''''''''''''''''''''''''''''''''''''''''''''''''
sql = " INSERT INTO tbl_TurnAround ( TestCode, CodeDesc, CntCode, SellPrice, who, [where], ReqEntRsltAvgTA, ReqEntRsltMaxTA, ReqEntRsltMinTA, RsltEntAuthAvgTA, RsltEntAuthMaxTA, RsltEntAuthTA, ReqEntAuthAvgTA, ReqEntAuthMaxTA, RsltEntAuthMinTA, DataDate, DataSource )" '& GetPath & "\PathlogyAgregate.mdb"
sql = sql & dbPath
sql = sql & " SELECT qryBMI_Turnaround.[Test Code], qryBMI_Turnaround.Desc, Count(qryBMI_Turnaround.[Test Code]) AS [CountOfTest Code], qryBMI_Turnaround.Sell, qryBMI_Turnaround.Clinician, qryBMI_Turnaround.[Source(Locn)], Format(Avg([ReqEntRslt]/60),'Fixed') AS ReqEntRsltAvgTA, Format(Max([ReqEntRslt]/60),'Fixed') AS ReqEntRsltMaxTA, Format(Min([ReqEntRslt]/60),'Fixed') AS ReqEntRsltMinTA, Format(Avg([RsltEntAuth]/60),'Fixed') AS RsltEntAuthAvgTA, Format(Max([RsltEntAuth]/60),'Fixed') AS RsltEntAuthMaxTA, Format(Min([RsltEntAuth]/60),'Fixed') AS RsltEntAuthTA, Format(Avg([ReqEntAuth]/60),'Fixed') AS ReqEntAuthAvgTA, Format(Max([ReqEntAuth]/60),'Fixed') AS ReqEntAuthMaxTA, Format(Min([RsltEntAuth]/60),'Fixed') AS RsltEntAuthMinTA, " & datDate & ", 'BMI' AS DataSource"
sql = sql & " FROM qryBMI_Turnaround"
sql = sql & " GROUP BY qryBMI_Turnaround.[Test Code], qryBMI_Turnaround.Desc, qryBMI_Turnaround.Sell, qryBMI_Turnaround.Clinician, qryBMI_Turnaround.[Source(Locn)], " & datDate & " , 'BMI'"
sql = sql & " HAVING (((qryBMI_Turnaround.Sell)>0));"