Hi, I have database with a form, frmPrimary, which is designed as my Switchboard of sorts. The database contains mountain classifications and reports. If I want to view the data for any classification in form view, then I have a button for each classification, eg, btnMunros, btnCorbetts which, when clicked have the following Event Procedure to a) close any currently open forms, and b) open the selected form as defined by the button. The OnClick Event Procedure on each button is shown below. (DoCmd “frmMunros” varies of course for each button)
Private Sub btnMunros_Click()
Dim obj As Object
Dim strName As String
For Each obj In Application.CurrentProject.AllForms
If obj.Name <> "frmPrimary" Then
DoCmd.Close acForm, obj.Name, acSaveNo
End If
Next obj
DoCmd.OpenForm "frmMunros", acFormDS
End Sub
This saves users having to close the current form before they open another one, as this procedure is repeated for each button OnClick. A “Home” button simply clears the screen if no other form is required.
These procedures all work, and have worked for some years, no problems.
Now, there is a requirement to have a similar procedure for when Reports are also being viewed, so, I was happy with that, I simply created additional buttons with the same procedure, only defining for Report, and expecting the same flawless operations. No such luck. Whichever classification is selected first, then the report displays as intended. However, when clicking on a subsequent report button, the open/active report simply beeps, shudders and stays stubbornly on the screen, and the newly selected report does not open.(If I close the open/active report with the standard report close button, it closes fine) The procedure called is shown below.
Private Sub btnMunrosABC_Click()
Dim obj As Object
Dim strName As String
For Each obj In Application.CurrentProject.AllReports
If obj.Name <> "frmPrimary" Then
DoCmd.Close acReport, obj.Name, acSaveNo
End If
Next obj
Me!txtStatus = "Munro"
ReportPage = 1
DoCmd.OpenReport "rptMunroABC", acViewReport
Me!txtStatus.Value = Null
End Sub
I know it is only an additional click to simply close each report as standard and then click the button to open the next report. But heck, isn’t that what we all want, the one click option. Thanks
I should add, I have viewed and tried a number of ways regarding my question, but none seem to work and close the report.
Private Sub btnMunros_Click()
Dim obj As Object
Dim strName As String
For Each obj In Application.CurrentProject.AllForms
If obj.Name <> "frmPrimary" Then
DoCmd.Close acForm, obj.Name, acSaveNo
End If
Next obj
DoCmd.OpenForm "frmMunros", acFormDS
End Sub
This saves users having to close the current form before they open another one, as this procedure is repeated for each button OnClick. A “Home” button simply clears the screen if no other form is required.
These procedures all work, and have worked for some years, no problems.
Now, there is a requirement to have a similar procedure for when Reports are also being viewed, so, I was happy with that, I simply created additional buttons with the same procedure, only defining for Report, and expecting the same flawless operations. No such luck. Whichever classification is selected first, then the report displays as intended. However, when clicking on a subsequent report button, the open/active report simply beeps, shudders and stays stubbornly on the screen, and the newly selected report does not open.(If I close the open/active report with the standard report close button, it closes fine) The procedure called is shown below.
Private Sub btnMunrosABC_Click()
Dim obj As Object
Dim strName As String
For Each obj In Application.CurrentProject.AllReports
If obj.Name <> "frmPrimary" Then
DoCmd.Close acReport, obj.Name, acSaveNo
End If
Next obj
Me!txtStatus = "Munro"
ReportPage = 1
DoCmd.OpenReport "rptMunroABC", acViewReport
Me!txtStatus.Value = Null
End Sub
I know it is only an additional click to simply close each report as standard and then click the button to open the next report. But heck, isn’t that what we all want, the one click option. Thanks
I should add, I have viewed and tried a number of ways regarding my question, but none seem to work and close the report.