open report from selection in combobox

Collapse
X
 
  • Time
  • Show
Clear All
new posts
  • Pierkes
    New Member
    • Feb 2013
    • 64

    open report from selection in combobox

    Hi,

    I use a table of reports to be able to select the right report.
    In the table i have the fields;

    ID_rap
    Rap_naam - the name the user will see in the cmb_rapselect
    Rap_cat - category of the report
    Rap_rapselect - the real name of the report (the name i have to use if i want the report to show

    I made a Query called Q_raps which lists all fields of the table.

    On a form i have 2 comboboxes;

    cmb_rapcat
    cmb_rap_rapsele ct

    The first combo lists the categories from the Qyery. Works fine

    The second combo the lists all reports from the category choosen in the first combo. The list consists of the names that the user sees, not the actual name of the report which is in the field [rap_nameselect]

    I now have a button on the form which, when clicked, should produce the report based on the report selected in the combo cmb_rapselect]. However, if i do that it will say that there is no report with that name.

    The code for the button;
    Code:
    Private Sub but_rapprint_Click()
    Dim strQL As String
    Dim rapsel As String
    strSQL = "SELECT * FROM Q_raps "
    strSQL = strSQL & "WHERE [Rap_naam] = me.[cmb_rap_rapselect]"
    rapsel = [Rap_select]
    DoCmd.OpenReport rapsel, acViewReport
    End Sub
    The code does not work....but i think iám close ?
    How can i make the button look at the right field called [Rap_select]?

    Help would be much appreciated.
    Thanks in advance.
    Pierkes
  • twinnyfo
    Recognized Expert Moderator Specialist
    • Nov 2011
    • 3662

    #2
    You are very close.

    Since your query includes all the fields, use the column property of the combo box:

    Code:
    Me.cmb_rap_rapselect.Column(3)
    Use column 3, because the column numbers start at 0, and I believe your fourth column should be the real Report name, correct?

    Comment

    • Pierkes
      New Member
      • Feb 2013
      • 64

      #3
      Originally posted by twinnyfo
      You are very close.

      Since your query includes all the fields, use the column property of the combo box:

      Code:
      Me.cmb_rap_rapselect.Column(3)
      Use column 3, because the column numbers start at 0, and I believe your fourth column should be the real Report name, correct?
      Hi, I now have this code;

      Code:
      strSQL = "SELECT * FROM Q_raps "
      strSQL = strSQL & "WHERE [Rap_select] = me.[cmb_rap_rapselect].Column(3)"
      DoCmd.OpenReport strSQL, acViewReport
      However, it does not open the report. It gives the message that it cannot open a report with the name '
      Code:
      "SELECT * FROM Q_raps "
      strSQL = strSQL & "WHERE [Rap_select] = me.[cmb_rap_rapselect].Column(3)"
      What am i doing wrong ?
      Thanks, Pierkes
      Last edited by zmbd; Jul 30 '14, 05:04 PM. Reason: [z{Placed the SQL in code tags}]

      Comment

      • twinnyfo
        Recognized Expert Moderator Specialist
        • Nov 2011
        • 3662

        #4
        Code:
        DoCmd.OpenReport Me.cmb_rap_rapselect.Column(3), acViewReport
        You can't open a Report just based ona query.

        Comment

        • Pierkes
          New Member
          • Feb 2013
          • 64

          #5
          Hi Twinnyfo,

          Thanks for helping me.
          The only code i have left now is;

          Code:
          DoCmd.OpenReport Me.cmb_rap_rapselect.Column(3), acViewReport
          However, now it gives an error because "the action or method requires a Report Name argument"

          Any ideas ?
          Regards,
          Pierkes

          Comment

          • Pierkes
            New Member
            • Feb 2013
            • 64

            #6
            Hi Twinnyfo,

            I managed !!!
            I had the bound column for the combobax wrong. I set it to column 3 an it worked !

            The code is now very simple;

            Code:
            DoCmd.OpenReport Me.cmb_rap_rapselect, acViewReport
            Thanks for your kind help !!
            Pierkes

            Comment

            Working...