Howdy, Stranger!

It looks like you're new here. If you want to get involved, click one of these buttons!

Categories

Print report based on selection from option group

ranravianranravian Member Posts: 20
I want the user to select a report from an option group and have a command button that receives that choice and opens the report in print preview. Can someone tell me what's wrong with this code? Thanks!!!

Private Sub OK_Click()
Me.Visible = False
Select Case Me!ReportToPrint
Case 1
DoCmd.OpenReport "1st Quarter", acViewPreview
Case 2
DoCmd.OpenReport "2nd Quarter", acViewPreview
Case 3
DoCmd.OpenReport "3rd Quarter", acViewPreview
Case 4
DoCmd.OpenReport "4th Quarter", acViewPreview
If IsNull("View/Print Reports") Then
DoCmd.CancelEvent

End If
End Select
DoCmd.Close acForm, "View/Print Reports"

End Sub

Comments

  • splansingsplansing Member Posts: 140
    : I want the user to select a report from an option group and have a command button that receives that choice and opens the report in print preview. Can someone tell me what's wrong with this code? Thanks!!!
    :
    : Private Sub OK_Click()
    : Me.Visible = False
    : Select Case Me!ReportToPrint
    : Case 1
    : DoCmd.OpenReport "1st Quarter", acViewPreview
    : Case 2
    : DoCmd.OpenReport "2nd Quarter", acViewPreview
    : Case 3
    : DoCmd.OpenReport "3rd Quarter", acViewPreview
    : Case 4
    : DoCmd.OpenReport "4th Quarter", acViewPreview
    : If IsNull("View/Print Reports") Then
    : DoCmd.CancelEvent
    :
    : End If
    : End Select
    : DoCmd.Close acForm, "View/Print Reports"
    :
    : End Sub
    :
    :
    Well, first of all you can skip the me.visible = false part. That's just an unnecessary complication.

    If you aren't getting the report you want, perhaps your drop-down Me!ReportToPrint isn't specific enough. Is this a multi-column drop-down? Do you need maybe to do your Select Case Me!ReportToPrint.Column(0), or something like that, to make sure you are getting the right value?

    Troubleshoot as follows:

    Replace
    "Me.Visible = False"
    With
    "Msgbox Me!ReportToPrint"

    If you get a message box that is the title of a report instead of a 1,2,3,4, then you are probably looking at the wrong column of me!ReportToPrint.
  • ranravianranravian Member Posts: 20
    : : I want the user to select a report from an option group and have a command button that receives that choice and opens the report in print preview. Can someone tell me what's wrong with this code? Thanks!!!
    : :
    : : Private Sub OK_Click()
    : : Me.Visible = False
    : : Select Case Me!ReportToPrint
    : : Case 1
    : : DoCmd.OpenReport "1st Quarter", acViewPreview
    : : Case 2
    : : DoCmd.OpenReport "2nd Quarter", acViewPreview
    : : Case 3
    : : DoCmd.OpenReport "3rd Quarter", acViewPreview
    : : Case 4
    : : DoCmd.OpenReport "4th Quarter", acViewPreview
    : : If IsNull("View/Print Reports") Then
    : : DoCmd.CancelEvent
    : :
    : : End If
    : : End Select
    : : DoCmd.Close acForm, "View/Print Reports"
    : :
    : : End Sub
    : :
    : :
    : Well, first of all you can skip the me.visible = false part. That's just an unnecessary complication.
    :
    : If you aren't getting the report you want, perhaps your drop-down Me!ReportToPrint isn't specific enough. Is this a multi-column drop-down? Do you need maybe to do your Select Case Me!ReportToPrint.Column(0), or something like that, to make sure you are getting the right value?
    :
    : Troubleshoot as follows:
    :
    : Replace
    : "Me.Visible = False"
    : With
    : "Msgbox Me!ReportToPrint"
    :
    : If you get a message box that is the title of a report instead of a 1,2,3,4, then you are probably looking at the wrong column of me!ReportToPrint.
    :
    Thanks for responding to this post. I figured it out. See below.

    If Me.Frame2 = 1 Then
    DoCmd.OpenReport "1st Quarter", acPreview

    ElseIf Me.Frame2 = 2 Then
    DoCmd.OpenReport "2nd Quarter", acPreview

    ElseIf Me.Frame2 = 3 Then
    DoCmd.OpenReport "3rd Quarter", acPreview

    ElseIf Me.Frame2 = 4 Then
    DoCmd.OpenReport "4th Quarter", acPreview

    Else
    DoCmd.CancelEvent
    End If

    Now I have a different problem. I am using parameter querys to retrieve the year and quarter. I have it set up so that they enter 1,2,3,or 4 for the quarter and the 4 digit year. I want to catch errors, not btwn. 1 and 4 or the years before 2005. How do I program this in vb from a parameter query.
  • splansingsplansing Member Posts: 140
    : : : I want the user to select a report from an option group and have a command button that receives that choice and opens the report in print preview. Can someone tell me what's wrong with this code? Thanks!!!
    : : :
    : : : Private Sub OK_Click()
    : : : Me.Visible = False
    : : : Select Case Me!ReportToPrint
    : : : Case 1
    : : : DoCmd.OpenReport "1st Quarter", acViewPreview
    : : : Case 2
    : : : DoCmd.OpenReport "2nd Quarter", acViewPreview
    : : : Case 3
    : : : DoCmd.OpenReport "3rd Quarter", acViewPreview
    : : : Case 4
    : : : DoCmd.OpenReport "4th Quarter", acViewPreview
    : : : If IsNull("View/Print Reports") Then
    : : : DoCmd.CancelEvent
    : : :
    : : : End If
    : : : End Select
    : : : DoCmd.Close acForm, "View/Print Reports"
    : : :
    : : : End Sub
    : : :
    : : :
    : : Well, first of all you can skip the me.visible = false part. That's just an unnecessary complication.
    : :
    : : If you aren't getting the report you want, perhaps your drop-down Me!ReportToPrint isn't specific enough. Is this a multi-column drop-down? Do you need maybe to do your Select Case Me!ReportToPrint.Column(0), or something like that, to make sure you are getting the right value?
    : :
    : : Troubleshoot as follows:
    : :
    : : Replace
    : : "Me.Visible = False"
    : : With
    : : "Msgbox Me!ReportToPrint"
    : :
    : : If you get a message box that is the title of a report instead of a 1,2,3,4, then you are probably looking at the wrong column of me!ReportToPrint.
    : :
    : Thanks for responding to this post. I figured it out. See below.
    :
    : If Me.Frame2 = 1 Then
    : DoCmd.OpenReport "1st Quarter", acPreview
    :
    : ElseIf Me.Frame2 = 2 Then
    : DoCmd.OpenReport "2nd Quarter", acPreview
    :
    : ElseIf Me.Frame2 = 3 Then
    : DoCmd.OpenReport "3rd Quarter", acPreview
    :
    : ElseIf Me.Frame2 = 4 Then
    : DoCmd.OpenReport "4th Quarter", acPreview
    :
    : Else
    : DoCmd.CancelEvent
    : End If
    :
    : Now I have a different problem. I am using parameter querys to retrieve the year and quarter. I have it set up so that they enter 1,2,3,or 4 for the quarter and the 4 digit year. I want to catch errors, not btwn. 1 and 4 or the years before 2005. How do I program this in vb from a parameter query.
    :
    Geez, just build a form to take the input already and be done with it. You can insert your validation rules right there in the field properties and have this finished in a few minutes.
Sign In or Register to comment.