Need help with

C

CH

I currently have the coding that allows me to "Print only the Current
Record" to a report. That report is named "rptAllAreas" and the
coding works fine and looks like this:

******************** Code Start *********************
Private Sub cmdPrint_Click()

Dim strReportName As String
Dim strCriteria As String

If NewRecord Then
MsgBox "This record contains no saved data or is currently in
Edit mode. Use the arrow buttons to select another record, then
reselect." _, vbInformation, "Invalid Action"
Exit Sub
Else
strReportName = "rptAllAreas"
strCriteria = "[ID]= " & Me![ID]
DoCmd.OpenReport strReportName, acViewNormal, , strCriteria
End If
End Sub
'******************** Code End ************************

What I am looking to do (I am a newbie) is to extend this "Print only
the Current Record" ability. I want to include coding that instead
of printing the one report, would print one of the three (3) following
reports:
rptAllAreas
rptABCArea
rptXYZArea
This would be based on the "Select Area" field (strArea) of the
displayed record. Could someone provide any help with the coding that
would be involved, and how it includes the above pieces?

Thanks..CH
 
J

John Spencer

You need to change strReportname using an if or case statement.

******************** Code Start *********************
Private Sub cmdPrint_Click()

Dim strReportName As String
Dim strCriteria As String

If NewRecord Then
MsgBox "This record contains no saved data or is currently in
Edit mode. Use the arrow buttons to select another record, then
reselect." _, vbInformation, "Invalid Action"
Exit Sub
Else
'Assign a default value for the report name
strReportName = "rptAllAreas"

'Change strReportName's value if needed
SELECT Case Me.StrArea
' Don't really need the next two lines since value is
' already set to rptAllAreas
' Case "SomeValue"
' strReportName = "rptAllAreas"
Case "Some Other Value"
strReportName = "rptABCArea"
Case "A Third Value"
strReportName = "rptXYZArea"
End Select
strCriteria = "[ID]= " & Me![ID]
DoCmd.OpenReport strReportName, acViewNormal, , strCriteria
End If
End Sub
'******************** Code End ************************
 

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