Open different reports from the one control based on control value

G

Guest

I have a Report Contol, in a Form,with 3 possible values: Yes; No and EP
If control is set to Yes, no report will be generated, which is what I want.
Double Clicking opens ReportA if the control is set to No
I would like to have ReportB open if the control is set to EP

Currently the code is:

Private Sub Report_DblClick(Cancel As Integer)
On Error GoTo Err_Report_DblClick

Dim stDocName As String

stDocName = "ReportA"

stLinkCriteria = "[ContactID]=" & Me![ContactID]
DoCmd.OpenReport stDocName, acPreview, , stLinkCriteria

Exit_Report_DblClick:
Exit Sub

Err_Report_DblClick:
MsgBox Err.Description
Resume Exit_Report_DblClick

End Sub

I can add a line so both ReportB opens as well as ReportA, but it would be
nice to only open the specific report. Both reports need to open based on the
ContactID.

Any suggestions out there?
 
G

Guest

Try adding something like this:

Dim strReporControl As String

stReportControl = me.[YourReportControl]
stLinkCriteria = "[ContactID]=" & Me![ContactID]

Select Case stReportControl
Case "Yes"
'Do Nothing
Case "No"
DoCmd.OpenReport "ReportA", acPreview, , stLinkCriteria
Case "EP"
DoCmd.OpenReport "ReportB", acPreview, , stLinkCriteria
End Select
 
G

Guest

Just fantastic Adam ... you just saved me a whole lot of time. Really
appreciate your assistance

John

Adam Milligan said:
Try adding something like this:

Dim strReporControl As String

stReportControl = me.[YourReportControl]
stLinkCriteria = "[ContactID]=" & Me![ContactID]

Select Case stReportControl
Case "Yes"
'Do Nothing
Case "No"
DoCmd.OpenReport "ReportA", acPreview, , stLinkCriteria
Case "EP"
DoCmd.OpenReport "ReportB", acPreview, , stLinkCriteria
End Select



j0hnt52 said:
I have a Report Contol, in a Form,with 3 possible values: Yes; No and EP
If control is set to Yes, no report will be generated, which is what I want.
Double Clicking opens ReportA if the control is set to No
I would like to have ReportB open if the control is set to EP

Currently the code is:

Private Sub Report_DblClick(Cancel As Integer)
On Error GoTo Err_Report_DblClick

Dim stDocName As String

stDocName = "ReportA"

stLinkCriteria = "[ContactID]=" & Me![ContactID]
DoCmd.OpenReport stDocName, acPreview, , stLinkCriteria

Exit_Report_DblClick:
Exit Sub

Err_Report_DblClick:
MsgBox Err.Description
Resume Exit_Report_DblClick

End Sub

I can add a line so both ReportB opens as well as ReportA, but it would be
nice to only open the specific report. Both reports need to open based on the
ContactID.

Any suggestions out there?
 

Ask a Question

Want to reply to this thread or ask your own question?

You'll need to choose a username for the site, which only take a couple of moments. After that, you can post your question and our members will help you out.

Ask a Question

Top