Hello,
I have spent all day debugging issues having to do with passing variables to my function. I finally know that the variables are passing and the sql statement is formatted correctly.
The main problem I am having is that when I create the recordset no matter how I do it whether I use the variables I pass in or if I hard code the variables in I do not think its actually returning any results.
Is there something I am missing to actually load the recordset?
Function MedianAutoF(pDisposition As String, pFacility As String, pStartDate As Date, pEndDate As Date) As String
Dim rs As Recordset
Dim strSQL As String
Dim n As Long
Dim sglHold As Long
Dim mainrs As Recordset
Dim mainsql As String
Dim ntotal As Long
mainsql = "SELECT tble_TempLOSData.PtAcctNbr, tble_TempLOSData.AdmitDateTime, tble_TempLOSData.LOS, tble_TempLOSData.DispID, tble_TempLOSData.FacilityID " & _
"FROM tble_TempLOSData " & _
"WHERE (((tble_TempLOSData.AdmitDateTime) Between #" & pStartDate & "# And #" & pEndDate & "#)" & _
"AND ((tble_TempLOSData.DispID)=" & pDisposition & ") AND ((tble_TempLOSData.FacilityID)=" & pFacility & "));"
'Testing to see if any records come back always get false
Set mainrs = CurrentDb.OpenRecordset(mainsql)
If mainrs.RecordCount > 1 Then
Debug.Print "true"
Else
Debug.Print "false"
End If
'mainsql = "SELECT tble_TempLOSData.PtAcctNbr, tble_TempLOSData.AdmitDateTime, tble_TempLOSData.LOS, tble_TempLOSData.DispID, tble_TempLOSData.FacilityID INTO TEMPTABLE " & _
'"FROM tble_TempLOSData " & _
'"WHERE (((tble_TempLOSData.AdmitDateTime) Between #" & pStartDate & "# And #" & pEndDate & "#)" & _
'" AND ((tble_TempLOSData.DispID)=" & pDisposition & ") AND ((tble_TempLOSData.FacilityID)=" & pFacility & "));"
'strSQL = "SELECT * FROM TEMPTABLE WHERE " & TempTable.LOS & ">=0 Order by " & TempTable.LOS & ";"
'Set rs = CurrentDb.OpenRecordset(strSQL)
'rs.MoveLast
'n = rs.RecordCount
'rs.Move -Int(n / 2)
'If n Mod 2 = 1 Then 'odd number of elements
' MedianAutoF = rs(LOS)
'Else 'even number of elements
' sglHold = rs(LOS)
' rs.MoveNext
'sglHold = sglHold + rs(LOS)
'MedianAutoF = sglHold / 2
'End If
'rs.Close
End Function
I have spent all day debugging issues having to do with passing variables to my function. I finally know that the variables are passing and the sql statement is formatted correctly.
The main problem I am having is that when I create the recordset no matter how I do it whether I use the variables I pass in or if I hard code the variables in I do not think its actually returning any results.
Is there something I am missing to actually load the recordset?
Function MedianAutoF(pDisposition As String, pFacility As String, pStartDate As Date, pEndDate As Date) As String
Dim rs As Recordset
Dim strSQL As String
Dim n As Long
Dim sglHold As Long
Dim mainrs As Recordset
Dim mainsql As String
Dim ntotal As Long
mainsql = "SELECT tble_TempLOSData.PtAcctNbr, tble_TempLOSData.AdmitDateTime, tble_TempLOSData.LOS, tble_TempLOSData.DispID, tble_TempLOSData.FacilityID " & _
"FROM tble_TempLOSData " & _
"WHERE (((tble_TempLOSData.AdmitDateTime) Between #" & pStartDate & "# And #" & pEndDate & "#)" & _
"AND ((tble_TempLOSData.DispID)=" & pDisposition & ") AND ((tble_TempLOSData.FacilityID)=" & pFacility & "));"
'Testing to see if any records come back always get false
Set mainrs = CurrentDb.OpenRecordset(mainsql)
If mainrs.RecordCount > 1 Then
Debug.Print "true"
Else
Debug.Print "false"
End If
'mainsql = "SELECT tble_TempLOSData.PtAcctNbr, tble_TempLOSData.AdmitDateTime, tble_TempLOSData.LOS, tble_TempLOSData.DispID, tble_TempLOSData.FacilityID INTO TEMPTABLE " & _
'"FROM tble_TempLOSData " & _
'"WHERE (((tble_TempLOSData.AdmitDateTime) Between #" & pStartDate & "# And #" & pEndDate & "#)" & _
'" AND ((tble_TempLOSData.DispID)=" & pDisposition & ") AND ((tble_TempLOSData.FacilityID)=" & pFacility & "));"
'strSQL = "SELECT * FROM TEMPTABLE WHERE " & TempTable.LOS & ">=0 Order by " & TempTable.LOS & ";"
'Set rs = CurrentDb.OpenRecordset(strSQL)
'rs.MoveLast
'n = rs.RecordCount
'rs.Move -Int(n / 2)
'If n Mod 2 = 1 Then 'odd number of elements
' MedianAutoF = rs(LOS)
'Else 'even number of elements
' sglHold = rs(LOS)
' rs.MoveNext
'sglHold = sglHold + rs(LOS)
'MedianAutoF = sglHold / 2
'End If
'rs.Close
End Function