M
Matt Williamson
I'm creating a SQL passthrough query to run a stored proc from code. When I
do this after creating the query, I'm getting prompted for a Data source any
time I run it and it doesn't always take, so sometime I get prompted
multiple times before it runs. Since it's the source for a cross tab query
that is the datasource for a report, it's getting very annoying. I was
changing the datasource to a local table just so I can edit the report and
then changing it back but that has stopped working since I dynamically
started creating the query from code. If I create the Pass through from
Access through the menu, it works without the prompting but as soon as I do
it from code, it starts the prompting. Here is the code I'm using to create
the query:
Private Sub cmdRunReport_Click()
lblDateForReport.Caption = CStr(Me.dFrom.Value & " - " & Me.dTo.Value)
Select Case Me.ReportSelect.Value
Case 1
Call Runstoredproc("pContDist")
DoCmd.OpenReport "Contributions & Distributions Totals", acViewPreview
Case 2
Call Runstoredproc("pContDist")
DoCmd.OpenReport "Details by SalesOffice", acViewPreview
Case Else
MsgBox "Select One of the reports to run."
End Select
Public Function Runstoredproc(sProcName As String) As Boolean
Dim sConnect As String, sSQL As String
Dim dbs As Database, qdf As QueryDef
sConnect = "ODBC;Provider=SQLNCLI; Server=Server\Instance; Database=Scratch;
Trusted_Connection=yes;"
Set dbs = CurrentDb
Set qdf = dbs.QueryDefs("qryCurrentProc")
sSQL = "exec " & sProcName & " @StartDate=" & _
"'" & Me.dFrom.Value & "'" & ",@EndDate=" & "'" & Me.dTo.Value & "'"
Debug.Print sSQL
qdf.SQL = sSQL
qdf.Connect = sConnect
End Function
Do I need to add something to the code to get the connection to persist?
TIA
Matt
do this after creating the query, I'm getting prompted for a Data source any
time I run it and it doesn't always take, so sometime I get prompted
multiple times before it runs. Since it's the source for a cross tab query
that is the datasource for a report, it's getting very annoying. I was
changing the datasource to a local table just so I can edit the report and
then changing it back but that has stopped working since I dynamically
started creating the query from code. If I create the Pass through from
Access through the menu, it works without the prompting but as soon as I do
it from code, it starts the prompting. Here is the code I'm using to create
the query:
Private Sub cmdRunReport_Click()
lblDateForReport.Caption = CStr(Me.dFrom.Value & " - " & Me.dTo.Value)
Select Case Me.ReportSelect.Value
Case 1
Call Runstoredproc("pContDist")
DoCmd.OpenReport "Contributions & Distributions Totals", acViewPreview
Case 2
Call Runstoredproc("pContDist")
DoCmd.OpenReport "Details by SalesOffice", acViewPreview
Case Else
MsgBox "Select One of the reports to run."
End Select
Public Function Runstoredproc(sProcName As String) As Boolean
Dim sConnect As String, sSQL As String
Dim dbs As Database, qdf As QueryDef
sConnect = "ODBC;Provider=SQLNCLI; Server=Server\Instance; Database=Scratch;
Trusted_Connection=yes;"
Set dbs = CurrentDb
Set qdf = dbs.QueryDefs("qryCurrentProc")
sSQL = "exec " & sProcName & " @StartDate=" & _
"'" & Me.dFrom.Value & "'" & ",@EndDate=" & "'" & Me.dTo.Value & "'"
Debug.Print sSQL
qdf.SQL = sSQL
qdf.Connect = sConnect
End Function
Do I need to add something to the code to get the connection to persist?
TIA
Matt