OasisUnknown
New Member
- Joined
- Oct 15, 2015
- Messages
- 46
Hello Everyone,
So far this forum has been an excellent resource so I thought I would try another question for the group.
I have a report that displays information about employees.
On a main menu form I have two different buttons that both open this one report about the employees.
What I am trying to do is update the header label depending on which button gets pressed.
currently I am doing this by passing the label I want through the open args parameters.
button one
button two
individually these two buttons work fine on their own and the label updates.
My question and problem comes when the report is already open and button 2 gets clicked.
The report data will open and update correctly (ie I get the false report) but the label never updates.
I am assuming this happens because I have the label updating on the reports on load procedure and because the report is already loaded the new label never gets updated.
I have also tried the on open procedure but this does not run the label update code either.
A work around I have created was a pre check open method that checks to see if the report is loaded and if it is then it closes the report.
but to me this is clunky.
I have to call the preopen method and then open my report in every instance that I want to open a report.
Any one have any suggestions on how I could do this better?
So far this forum has been an excellent resource so I thought I would try another question for the group.
I have a report that displays information about employees.
On a main menu form I have two different buttons that both open this one report about the employees.
What I am trying to do is update the header label depending on which button gets pressed.
currently I am doing this by passing the label I want through the open args parameters.
button one
Code:
DoCmd.OpenReport "myRpt", acViewReport, , "[CD Coded] = true", acWindowNormal, "True Code Rpt"
button two
Code:
DoCmd.OpenReport "myRpt", acViewReport, , "[CD Coded] = false", acWindowNormal, "False Code Rpt"
individually these two buttons work fine on their own and the label updates.
My question and problem comes when the report is already open and button 2 gets clicked.
The report data will open and update correctly (ie I get the false report) but the label never updates.
I am assuming this happens because I have the label updating on the reports on load procedure and because the report is already loaded the new label never gets updated.
I have also tried the on open procedure but this does not run the label update code either.
A work around I have created was a pre check open method that checks to see if the report is loaded and if it is then it closes the report.
Code:
Public Sub PreCheckOpenReportAndClose(targetReport As String)
On Error GoTo Error_Handler
If Application.CurrentProject.AllReports(targetReport).IsLoaded = True Then
'close report
DoCmd.Close acReport, targetReport
End If
Error_Handler_Exit:
On Error Resume Next
Exit Sub
Error_Handler:
Call DisplayErrorMessage(targetReport)
Resume Error_Handler_Exit
End Sub
but to me this is clunky.
I have to call the preopen method and then open my report in every instance that I want to open a report.
Any one have any suggestions on how I could do this better?