Reputation: 3
I have a button that is already assigned to open a Report. What I want is that when the user enables a checkbox, I want the OnClick
action of the button that I already assigned to change to open a different report.
So my logic goes like this:
button 1 = docmd.openreport
when user checkbox = true
button 1 = docmd.openreport2
Is that possible?
Private Sub Check130_Click()
If Me.Check130.Value = True Then
Me.Command1871.OnClick() = DoCmd.OpenReport "rptLoansNew", acViewReport, "", "", acNormal
End Sub
But it show syntax error.
In fact I'm clueless how to achieve this.
Upvotes: 0
Views: 149
Reputation: 55831
You can do something like this:
Private Sub YourButton_Click()
Dim ReportName As String
If Me!Check130.Value = True Then
ReportName = "rptLoansNew"
Else
ReportName = "rptLoansOld"
End If
DoCmd.OpenReport ReportName, acViewReport, "", "", acNormal
End Sub
And do rename your controls to something meaningful.
Upvotes: 1