pbuethe
Returning User
- Local time
- Today, 13:10
- Joined
- Apr 9, 2002
- Messages
- 210
In the following code I am getting the error “ODBC – call failed” error 3146, on the line
Set rstCaseInfoFiltered = qdfCurr.OpenRecordset
I had a previous version of this code which used a stored Access query instead of building the strSQL. That was working but was very slow. I am trying to use a passthrough query in order to speed it up.
Another factor which may or may not have anything to do with this is that we have recently switched from Windows 7 to Windows 10.
Thanks for your assistance.
Set rstCaseInfoFiltered = qdfCurr.OpenRecordset
Code:
Function basPreFill(strSample As String, strFacility As String, strCaseID As String)
Dim strWSFormName As String, strRationaleName As String, strSQL As String
Dim AcroApp As Acrobat.CAcroApp
Dim theWSForm As Acrobat.CAcroPDDoc, theRationale As Acrobat.CAcroPDDoc
Dim rstCaseInfoFiltered As DAO.Recordset
Dim jso As Object
Dim strfilename As String
Dim strFieldName As String
Dim dbCurr As DAO.Database
Dim qdfCurr As DAO.QueryDef
Dim i As Integer
Dim SNotifyDate As String, DxField As String, ProcField As String
strWSFormName = conMainFolder & strSample & "\" & strFacility & "\" & strCaseID & "\" & strCaseID & "_Worksheet.pdf"
Set AcroApp = CreateObject("AcroExch.App")
Set theWSForm = CreateObject("AcroExch.PDDoc")
If Dir(strWSFormName) <> "" Then
MsgBox strWSFormName & " already exists. "
Exit Function
End If
strfilename = "V:\Master_DB\eChart\Worksheet Template\011_NYSCAID Retrospective Review Worksheet_2018-08-01_R3Enable.pdf"
If theWSForm.Open(strfilename) = False Then
Debug.Print strfilename & " not found"
Exit Function
End If
' changed to pass through query for rstCaseInfoFiltered to speed up - P. Buethe 8/7/2019
Set dbCurr = CurrentDb()
Set qdfCurr = dbCurr.CreateQueryDef("")
strSQL = "SELECT dbo.tblWkshtHeader.CaseNbr, dbo.tblWkshtHeader.ReviewSite, " & vbCrLf
strSQL = strSQL & " dbo.tblWkshtHeader.Flag1, dbo.tblWkshtHeader.Flag2, dbo.tblWkshtHeader.Flag3," & vbCrLf
strSQL = strSQL & " dbo.tblWkshtHeader.SampleNbr, dbo.tblWkshtHeader.County," & vbCrLf
strSQL = strSQL & " dbo.tblWkshtHeader.NMonth, dbo.tblWkshtHeader.NDay, " & vbCrLf
strSQL = strSQL & " dbo.tblWkshtHeader.NYear, dbo.tblWkshtHeader.Provider," & vbCrLf
strSQL = strSQL & " dbo.tblWkshtHeader.PatientName, dbo.tblWkshtHeader.MedRecNbr," & vbCrLf
strSQL = strSQL & " dbo.tblWkshtHeader.MedicaidID, dbo.tblWkshtHeader.AdmitDate," & vbCrLf
strSQL = strSQL & " dbo.tblWkshtHeader.DischDate, dbo.tblWkshtHeader.Sex," & vbCrLf
strSQL = strSQL & " dbo.tblWkshtHeader.LOS, dbo.tblWkshtHeader.DOB, dbo.tblWkshtHeader.Age," & vbCrLf
strSQL = strSQL & " dbo.tblWkshtHeader.BirthWeight, dbo.tblWkshtHeader.SequenceNbr," & vbCrLf
strSQL = strSQL & " dbo.tblWkshtHeader.DRG, dbo.tblWkshtHeader.DRGDesc," & vbCrLf
strSQL = strSQL & " dbo.tblWkshtHeader.DRGSOI, dbo.tblWkshtDRG.LowTrim," & vbCrLf
strSQL = strSQL & " dbo.tblWkshtDRG.HighTrim, dbo.tblWkshtDRG.SIW, dbo.tblWkshtDRG.Dx1," & vbCrLf
strSQL = strSQL & " dbo.tblWkshtDRG.Dx2, dbo.tblWkshtDRG.Dx3, dbo.tblWkshtDRG.Dx4," & vbCrLf
strSQL = strSQL & " dbo.tblWkshtDRG.Dx5, dbo.tblWkshtDRG.Dx6, dbo.tblWkshtDRG.Dx7," & vbCrLf
strSQL = strSQL & " dbo.tblWkshtDRG.Dx8, dbo.tblWkshtDRG.Dx9, dbo.tblWkshtDRG.Dx10," & vbCrLf
strSQL = strSQL & " dbo.tblWkshtDRG.Dx11, dbo.tblWkshtDRG.Dx12, dbo.tblWkshtDRG.Dx13," & vbCrLf
strSQL = strSQL & " dbo.tblWkshtDRG.Dx14, dbo.tblWkshtDRG.Dx15, dbo.tblWkshtDRG.Dx16," & vbCrLf
strSQL = strSQL & " dbo.tblWkshtDRG.Dx17, dbo.tblWkshtDRG.Dx18, dbo.tblWkshtDRG.Dx19," & vbCrLf
strSQL = strSQL & " dbo.tblWkshtDRG.Dx20, dbo.tblWkshtDRG.Dx21, dbo.tblWkshtDRG.Dx22," & vbCrLf
strSQL = strSQL & " dbo.tblWkshtDRG.Dx23, dbo.tblWkshtDRG.Dx24, dbo.tblWkshtDRG.Dx25," & vbCrLf
strSQL = strSQL & " dbo.tblWkshtDRG.DxDesc1, dbo.tblWkshtDRG.DxDesc2," & vbCrLf
strSQL = strSQL & " dbo.tblWkshtDRG.DxDesc3, dbo.tblWkshtDRG.DxDesc4," & vbCrLf
strSQL = strSQL & " dbo.tblWkshtDRG.DxDesc5, dbo.tblWkshtDRG.DxDesc6," & vbCrLf
strSQL = strSQL & " dbo.tblWkshtDRG.DxDesc7, dbo.tblWkshtDRG.DxDesc8," & vbCrLf
strSQL = strSQL & " dbo.tblWkshtDRG.DxDesc9, dbo.tblWkshtDRG.DxDesc10," & vbCrLf
strSQL = strSQL & " dbo.tblWkshtDRG.DxDesc11, dbo.tblWkshtDRG.DxDesc12," & vbCrLf
strSQL = strSQL & " dbo.tblWkshtDRG.DxDesc13, dbo.tblWkshtDRG.DxDesc14," & vbCrLf
strSQL = strSQL & " dbo.tblWkshtDRG.DxDesc15, dbo.tblWkshtDRG.DxDesc16," & vbCrLf
strSQL = strSQL & " dbo.tblWkshtDRG.DxDesc17, dbo.tblWkshtDRG.DxDesc18," & vbCrLf
strSQL = strSQL & " dbo.tblWkshtDRG.DxDesc19, dbo.tblWkshtDRG.DxDesc20," & vbCrLf
strSQL = strSQL & " dbo.tblWkshtDRG.DxDesc21, dbo.tblWkshtDRG.DxDesc22," & vbCrLf
strSQL = strSQL & " dbo.tblWkshtDRG.DxDesc23, dbo.tblWkshtDRG.DxDesc24," & vbCrLf
strSQL = strSQL & " dbo.tblWkshtDRG.DxDesc25, dbo.tblWkshtDRG.Proc1, dbo.tblWkshtDRG.Proc2," & vbCrLf
strSQL = strSQL & " dbo.tblWkshtDRG.Proc3, dbo.tblWkshtDRG.Proc4, dbo.tblWkshtDRG.Proc5," & vbCrLf
strSQL = strSQL & " dbo.tblWkshtDRG.Proc6, dbo.tblWkshtDRG.Proc7, dbo.tblWkshtDRG.Proc8," & vbCrLf
strSQL = strSQL & " dbo.tblWkshtDRG.Proc9, dbo.tblWkshtDRG.Proc10, dbo.tblWkshtDRG.Proc11," & vbCrLf
strSQL = strSQL & " dbo.tblWkshtDRG.Proc12, dbo.tblWkshtDRG.Proc13, dbo.tblWkshtDRG.Proc14," & vbCrLf
strSQL = strSQL & " dbo.tblWkshtDRG.Proc15, dbo.tblWkshtDRG.Proc16, dbo.tblWkshtDRG.Proc17," & vbCrLf
strSQL = strSQL & " dbo.tblWkshtDRG.Proc18, dbo.tblWkshtDRG.Proc19, dbo.tblWkshtDRG.Proc20," & vbCrLf
strSQL = strSQL & " dbo.tblWkshtDRG.Proc21, dbo.tblWkshtDRG.Proc22, dbo.tblWkshtDRG.Proc23," & vbCrLf
strSQL = strSQL & " dbo.tblWkshtDRG.Proc24, dbo.tblWkshtDRG.Proc25, dbo.tblWkshtDRG.ProcDesc1," & vbCrLf
strSQL = strSQL & " dbo.tblWkshtDRG.ProcDesc2, dbo.tblWkshtDRG.ProcDesc3," & vbCrLf
strSQL = strSQL & "dbo.tblWkshtDRG.ProcDesc4, dbo.tblWkshtDRG.ProcDesc5," & vbCrLf
strSQL = strSQL & " dbo.tblWkshtDRG.ProcDesc6, dbo.tblWkshtDRG.ProcDesc7," & vbCrLf
strSQL = strSQL & " dbo.tblWkshtDRG.ProcDesc8, dbo.tblWkshtDRG.ProcDesc9," & vbCrLf
strSQL = strSQL & " dbo.tblWkshtDRG.ProcDesc10, dbo.tblWkshtDRG.ProcDesc11," & vbCrLf
strSQL = strSQL & " dbo.tblWkshtDRG.ProcDesc12, dbo.tblWkshtDRG.ProcDesc13," & vbCrLf
strSQL = strSQL & " dbo.tblWkshtDRG.ProcDesc14, dbo.tblWkshtDRG.ProcDesc15," & vbCrLf
strSQL = strSQL & " dbo.tblWkshtDRG.ProcDesc16, dbo.tblWkshtDRG.ProcDesc17," & vbCrLf
strSQL = strSQL & " dbo.tblWkshtDRG.ProcDesc18, dbo.tblWkshtDRG.ProcDesc19," & vbCrLf
strSQL = strSQL & " dbo.tblWkshtDRG.ProcDesc20, dbo.tblWkshtDRG.ProcDesc21," & vbCrLf
strSQL = strSQL & " dbo.tblWkshtDRG.ProcDesc22, dbo.tblWkshtDRG.ProcDesc23," & vbCrLf
strSQL = strSQL & " dbo.tblWkshtDRG.ProcDesc24, dbo.tblWkshtDRG.ProcDesc25," & vbCrLf
strSQL = strSQL & " dbo.tblWkshtDRG.DrgROM, dbo.tblDiagSOI.SOI1, dbo.tblDiagSOI.SOI2," & vbCrLf
strSQL = strSQL & " dbo.tblDiagSOI.SOI3, dbo.tblDiagSOI.SOI4, dbo.tblDiagSOI.SOI5," & vbCrLf
strSQL = strSQL & " dbo.tblDiagSOI.SOI6, dbo.tblDiagSOI.SOI7, dbo.tblDiagSOI.SOI8," & vbCrLf
strSQL = strSQL & " dbo.tblDiagSOI.SOI9, dbo.tblDiagSOI.SOI10, dbo.tblDiagSOI.SOI11," & vbCrLf
strSQL = strSQL & " dbo.tblDiagSOI.SOI12, dbo.tblDiagSOI.SOI13, dbo.tblDiagSOI.SOI14," & vbCrLf
strSQL = strSQL & " dbo.tblDiagSOI.SOI15, dbo.tblDiagSOI.SOI16, dbo.tblDiagSOI.SOI17," & vbCrLf
strSQL = strSQL & " dbo.tblDiagSOI.SOI18, dbo.tblDiagSOI.SOI19, dbo.tblDiagSOI.SOI20," & vbCrLf
strSQL = strSQL & " dbo.tblDiagSOI.SOI21, dbo.tblDiagSOI.SOI22, dbo.tblDiagSOI.SOI23," & vbCrLf
strSQL = strSQL & " dbo.tblDiagSOI.SOI24, dbo.tblDiagSOI.SOI25, dbo.tblWkshtDRG.POA1," & vbCrLf
strSQL = strSQL & " dbo.tblWkshtDRG.POA2, dbo.tblWkshtDRG.POA3, dbo.tblWkshtDRG.POA4," & vbCrLf
strSQL = strSQL & " dbo.tblWkshtDRG.POA5, dbo.tblWkshtDRG.POA6, dbo.tblWkshtDRG.POA7," & vbCrLf
strSQL = strSQL & " dbo.tblWkshtDRG.POA8, dbo.tblWkshtDRG.POA9, dbo.tblWkshtDRG.POA10," & vbCrLf
strSQL = strSQL & " dbo.tblWkshtDRG.POA11, dbo.tblWkshtDRG.POA12, dbo.tblWkshtDRG.POA13," & vbCrLf
strSQL = strSQL & " dbo.tblWkshtDRG.POA14, dbo.tblWkshtDRG.POA15, dbo.tblWkshtDRG.POA16," & vbCrLf
strSQL = strSQL & " dbo.tblWkshtDRG.POA17, dbo.tblWkshtDRG.POA18, dbo.tblWkshtDRG.POA19," & vbCrLf
strSQL = strSQL & " dbo.tblWkshtDRG.POA20, dbo.tblWkshtDRG.POA21, dbo.tblWkshtDRG.POA22," & vbCrLf
strSQL = strSQL & " dbo.tblWkshtDRG.POA23, dbo.tblWkshtDRG.POA24, dbo.tblWkshtDRG.POA25," & vbCrLf
strSQL = strSQL & " dbo.tblWkshtDRG.Dispo, dbo.tblWkshtDRG.DispoDesc, dbo.tblWkshtUtil.ClaimRef," & vbCrLf
strSQL = strSQL & " dbo.tblWkshtUtil.StartDate, dbo.tblWkshtUtil.EndDate, dbo.tblWkshtUtil.RC," & vbCrLf
strSQL = strSQL & " dbo.tblWkshtUtil.PayAmt, dbo.tblWkshtFlag.Admission AS AS1," & vbCrLf
strSQL = strSQL & " dbo.tblWkshtFlag.LOS AS AS2, dbo.tblWkshtFlag.DRG AS AS3," & vbCrLf
strSQL = strSQL & " dbo.tblWkshtFlag.Discharge AS AS4, dbo.tblWkshtFlag.NYPORTS AS AS5," & vbCrLf
strSQL = strSQL & " dbo.tblWkshtFlag.Quality AS AS6, dbo.tblWkshtFlag.Documentation AS AS7," & vbCrLf
strSQL = strSQL & " dbo.tblWkshtFlag.ALC AS AS8, dbo.tblWkshtFlag.Transfer AS AS9," & vbCrLf
strSQL = strSQL & " dbo.tblWkshtFlag.Mortality AS AS10, dbo.tblWkshtFlag.Complications AS AS11," & vbCrLf
strSQL = strSQL & " dbo.tblWkshtFlag.SAE AS AS12, dbo.tblWkshtFlag.CostOutlier AS AS13" & vbCrLf
strSQL = strSQL & " FROM (((dbo.tblWkshtHeader INNER JOIN dbo.tblWkshtUtil " & vbCrLf
strSQL = strSQL & " ON dbo.tblWkshtHeader.CaseNbr = dbo.tblWkshtUtil.CaseNbr)" & vbCrLf
strSQL = strSQL & " INNER JOIN dbo.tblWkshtDRG" & vbCrLf
strSQL = strSQL & " ON dbo.tblWkshtHeader.CaseNbr = dbo.tblWkshtDRG.CaseNbr)" & vbCrLf
strSQL = strSQL & " INNER JOIN dbo.tblDiagSOI" & vbCrLf
strSQL = strSQL & " ON dbo.tblWkshtHeader.CaseNbr = dbo.tblDiagSOI.CaseNbr)" & vbCrLf
strSQL = strSQL & " INNER JOIN dbo.tblWkshtFlag" & vbCrLf
strSQL = strSQL & " ON dbo.tblWkshtHeader.CaseNbr = dbo.tblWkshtFlag.CaseNbr" & vbCrLf
strSQL = strSQL & " WHERE CaseNbr = '" & strCaseID & "';"
qdfCurr.Connect = "ODBC;Description=Linkage to ChartCaidRetro;DRIVER=SQL Server;SERVER=AIMS-SQLSVR;Trusted_Connection=Yes;DATABASE=ChartCaidRetro;"
qdfCurr.SQL = strSQL
qdfCurr.ReturnsRecords = True
Set rstCaseInfoFiltered = qdfCurr.OpenRecordset
If rstCaseInfoFiltered.RecordCount <> 1 Then
'Debug.Print "Check case ID " & strCaseID
Exit Function
End If
I had a previous version of this code which used a stored Access query instead of building the strSQL. That was working but was very slow. I am trying to use a passthrough query in order to speed it up.
Another factor which may or may not have anything to do with this is that we have recently switched from Windows 7 to Windows 10.
Thanks for your assistance.