Hello,
I have a function I built that takes in values from a form. I am trying to add an additional sql statement to it so that I can have two separate record sets. The mainsql is the main recordset that I want the strSql recordset to be able to take from. I keep getting a Run Time Error Too few parameters expected. Expected 4, Run-time error '3061'. I can't figure out what other parameters it is looking for. I have confirmed that all of the parameters that I pass in are being passed in when I stepped through.
I bolded the section I get the error on.
Thank you in advance.
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 Integer
mainsql = "SELECT tble_TempLOSDate.Facility, tble_TempLOSDate.[Pt Acct Nbr], tble_TempLOSDate.Dispositions, tble_TempLOSDate.TL, tble_TempLOSDate.[AdmitDate&Time], tble_TempLOSDate.[DischargeDate&Time], tble_TempLOSDate.LOS, tble_TempLOSDate.DispID, tble_TempLOSDate.FacilityID " & _
"FROM tble_TempLOSDate " & _
"WHERE (((tble_TempLOSDate.[AdmitDate&Time]) Between [pStartDate] And [pEndDate]) AND ((tble_TempLOSDate.DispID)=pDisposition) AND ((tble_TempLOSDate.FacilityID)=pFacility));"
Set mainrs = CurrentDb.OpenRecordset(mainsql)
rs.MoveLast
ntotal = mainrs.RecordCount
strSQL = "SELECT " & LOS & " from " & mainsql & " WHERE " & LOS & ">=0 Order by " & 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(pfield)
Else 'even number of elements
sglHold = rs(pfield)
rs.MoveNext
sglHold = sglHold + rs(pfield)
MedianAutoF = sglHold / 2
End If
rs.Close
End Function
I have a function I built that takes in values from a form. I am trying to add an additional sql statement to it so that I can have two separate record sets. The mainsql is the main recordset that I want the strSql recordset to be able to take from. I keep getting a Run Time Error Too few parameters expected. Expected 4, Run-time error '3061'. I can't figure out what other parameters it is looking for. I have confirmed that all of the parameters that I pass in are being passed in when I stepped through.
I bolded the section I get the error on.
Thank you in advance.
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 Integer
mainsql = "SELECT tble_TempLOSDate.Facility, tble_TempLOSDate.[Pt Acct Nbr], tble_TempLOSDate.Dispositions, tble_TempLOSDate.TL, tble_TempLOSDate.[AdmitDate&Time], tble_TempLOSDate.[DischargeDate&Time], tble_TempLOSDate.LOS, tble_TempLOSDate.DispID, tble_TempLOSDate.FacilityID " & _
"FROM tble_TempLOSDate " & _
"WHERE (((tble_TempLOSDate.[AdmitDate&Time]) Between [pStartDate] And [pEndDate]) AND ((tble_TempLOSDate.DispID)=pDisposition) AND ((tble_TempLOSDate.FacilityID)=pFacility));"
Set mainrs = CurrentDb.OpenRecordset(mainsql)
rs.MoveLast
ntotal = mainrs.RecordCount
strSQL = "SELECT " & LOS & " from " & mainsql & " WHERE " & LOS & ">=0 Order by " & 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(pfield)
Else 'even number of elements
sglHold = rs(pfield)
rs.MoveNext
sglHold = sglHold + rs(pfield)
MedianAutoF = sglHold / 2
End If
rs.Close
End Function