Hello,
I have a pass through query that executes a stored procedure that will return results that I use on an MS access report. I have created the pass through query like I do for all of my forms and instead of putting it in the record source property I put code in the load event to populate the record source. This works fine for a form....but it doesn't work for a report. If I put the name of the pass through query into the report record source property it runs, but for some reason it doesn't update if I run the report again with different criteria.
How can I have a pass through query as the record source for a report and have it update everytime I run the report again? I checked the pass through query and it just holds the first parameter I ran the report with. If I remove the pass through query from the record source properties of the report it doesn't run at all. I set a breakpoint and its like it doesn't even get to the report load event, but it will open the report it will just have nothing in it.
Private Sub Report_Load()
Dim rs As DAO.Recordset
Dim db As Database
Dim rstEncounterDetails As DAO.Recordset
Dim strEncounterEmailSQLString As String
'Set the Encounber number variable equal to the first (and only in this case) argument passed in from the measure worklist.
strProvTbleID = [Forms]![frm_SendVarianceNotice]![ProvTbleID]
'Build SQL string to pass into sp_GetWorklistAMI based on user input parameters.
strEncounterEmailSQLString = "EXEC sp_GenerateVarianceEmailMainReport " & strProvTbleID
' Set database variable to current database.
Set db = CurrentDb
'Open QueryDef object.
Set qdf = db.QueryDefs("sp_GenerateVarianceEmailMainReport")
'Assign query def sql command to the sql string built form user selections.
qdf.SQL = strEncounterEmailSQLString
'Allow the stored procedure to return a result set to be bound.
qdf.ReturnsRecords = True
'Open Recordset object as a query def.
Set rstEncounterDetails = qdf.OpenRecordset()
If rstEncounterDetails.EOF Then
MsgBox ("There are no variances attached to this encounter")
Exit Sub
End If
'Move to the first record of the record set.
rstEncounterDetails.MoveFirst
'Bound the current form that is loading to the recordset returned by the stored procedure containing only user's selection.
Set Me.Recordset = rstEncounterDetails
End Sub
I have a pass through query that executes a stored procedure that will return results that I use on an MS access report. I have created the pass through query like I do for all of my forms and instead of putting it in the record source property I put code in the load event to populate the record source. This works fine for a form....but it doesn't work for a report. If I put the name of the pass through query into the report record source property it runs, but for some reason it doesn't update if I run the report again with different criteria.
How can I have a pass through query as the record source for a report and have it update everytime I run the report again? I checked the pass through query and it just holds the first parameter I ran the report with. If I remove the pass through query from the record source properties of the report it doesn't run at all. I set a breakpoint and its like it doesn't even get to the report load event, but it will open the report it will just have nothing in it.
Private Sub Report_Load()
Dim rs As DAO.Recordset
Dim db As Database
Dim rstEncounterDetails As DAO.Recordset
Dim strEncounterEmailSQLString As String
'Set the Encounber number variable equal to the first (and only in this case) argument passed in from the measure worklist.
strProvTbleID = [Forms]![frm_SendVarianceNotice]![ProvTbleID]
'Build SQL string to pass into sp_GetWorklistAMI based on user input parameters.
strEncounterEmailSQLString = "EXEC sp_GenerateVarianceEmailMainReport " & strProvTbleID
' Set database variable to current database.
Set db = CurrentDb
'Open QueryDef object.
Set qdf = db.QueryDefs("sp_GenerateVarianceEmailMainReport")
'Assign query def sql command to the sql string built form user selections.
qdf.SQL = strEncounterEmailSQLString
'Allow the stored procedure to return a result set to be bound.
qdf.ReturnsRecords = True
'Open Recordset object as a query def.
Set rstEncounterDetails = qdf.OpenRecordset()
If rstEncounterDetails.EOF Then
MsgBox ("There are no variances attached to this encounter")
Exit Sub
End If
'Move to the first record of the record set.
rstEncounterDetails.MoveFirst
'Bound the current form that is loading to the recordset returned by the stored procedure containing only user's selection.
Set Me.Recordset = rstEncounterDetails
End Sub