Results 1 to 4 of 4
  1. #1
    Join Date
    Apr 2007
    Location
    Weatherford TX (Between Fort Worth and Abilene)
    Posts
    57

    Unanswered: Open report based on paramaterized query with vba

    I need to open a report that is based on a parameterized query. The report can be opened from a variety of forms that users have to access to open the report. I know how to use the do command to open the report and pass a filter argument but that doesnít work if the report is based on parameters. I donít want to change the source of the parameters to a control on the form because this report can be accessed from several different forms and the query itself is used in several different reports showing different amounts of detail.

    Iíve always been taught that itís better to open a report with the data you want to see rather than opening a report and then applying a filter after it is opened. Even if I wanted to, Iím not allowed to change the report or the query so Iím stuck with the parameterized query and making it work. The query is fairly complex with several tables one of which has over 200,000 rows.
    he source of the parameters to a control on the form because this report can be accessed from several different forms and the query itself is used in several different reports showing different amounts of detail.

    I can use this code to open a form based on the parameterized query but when I tried to use it on a report I got a message ďThis feature is only available in and ADPĒ and my tables are based on ODBC tables from a pervasive database and not an sql server ADP.
    uery and making it work. The query is fairly complex with several tables one of which has over 200,000 rows.
    he source of the parameters to a control on the form because this report can be accessed from several different forms and the query itself is used in several different reports showing different amounts of detail.

    This is my code I can use to open a form
    Code:
    Private Sub Form_Open(Cancel As Integer)
        'This doesn't work on a report
        Dim mydb As dao.Database
        Dim Myqdf As dao.QueryDef
        Set mydb = CodeDb
        Set Myqdf = mydb.QueryDefs("qryPODetails")
        Myqdf.Parameters("WhatPO").Value = "0008009"
        Set Me.Recordset = Myqdf.OpenRecordset
    End Sub
    Is there any way to open this report as it is without removing the parameters and using a filter argument instead?

    I'm using MS Access 2010

  2. #2
    Join Date
    Nov 2004
    Location
    out on a limb
    Posts
    13,692
    Provided Answers: 59
    In this case, especially if the same query *wit the same parameters is expected to be used in multiple forms or reports then I'd:-

    either write the query (with the paremeters substituted to the query defs collection
    OR
    pull the values required from another form
    I'd rather be riding on the Tiger 800 or the Norton

  3. #3
    Join Date
    Apr 2007
    Location
    Weatherford TX (Between Fort Worth and Abilene)
    Posts
    57
    Thanks for the response

    I've done that type of thing before. create a criteria form for the report and then base the query paramaters on the value of the form. In the open even of the report open the Criteria form if its not open and go on from there. In order to do that you have to modify the report's open event and I don't have my bosses permission to do that. I'm stuck with using the paramaterized query.

    I don't think it can be done without modifying the report or the query

  4. #4
    Join Date
    Nov 2004
    Location
    out on a limb
    Posts
    13,692
    Provided Answers: 59
    so what you could do is wotk around that
    create a form that captures the parameters
    write a query, using those parameters and save the query in the querydefs collection overwriting any pre existing query of the same name
    use that query in each report / form as required

    Or talk to your boss and try to understsnd why your boss refuses permission to do things as I'd style it the right way. There may be good sysyems principles behind that view or it could reflect the only way your boss thinks it can be done. Sometimes managers dont have enough knowledge or experience or expertese, sometimes managers have a little knowledge and force others to follow that lack of knowledge down blind alleys
    I'd rather be riding on the Tiger 800 or the Norton

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts
  •