Results 1 to 13 of 13
  1. #1
    ShadeRF is offline Novice
    Windows 7 64bit Access 2010 32bit
    Join Date
    May 2011
    Posts
    24

    Choosing Report


    I have a macro that runs two queries then opens a report. I'd like to have it choose between two reports based on information in the query.

    I have a column Brand in the query. If the query returns BrandX I want to open report 1 and if it returns BrandY i want to open report 2. How can I accomplish this? Thanks!

  2. #2
    hertfordkc is offline 18 year novice
    Windows XP Access 2007
    Join Date
    Mar 2011
    Posts
    481

    Try this link.

    Quote Originally Posted by ShadeRF View Post
    I have a macro that runs two queries then opens a report. I'd like to have it choose between two reports based on information in the query.

    I have a column Brand in the query. If the query returns BrandX I want to open report 1 and if it returns BrandY i want to open report 2. How can I accomplish this? Thanks!
    -------------------------------------------------------------------------

    http://office.microsoft.com/en-us/ac...005188429.aspx

  3. #3
    ShadeRF is offline Novice
    Windows 7 64bit Access 2010 32bit
    Join Date
    May 2011
    Posts
    24
    I put the condition in the WHERE box, but I believe this doesn't actually decide if the report opens or not. On my Macro I have two openreport peices, but I only want one to open based on what is in the Brand field on the Query.

  4. #4
    hertfordkc is offline 18 year novice
    Windows XP Access 2007
    Join Date
    Mar 2011
    Posts
    481

    I'm afraid I'm not quite seeing the whole picture.

    Can post just the macro text and the query SQL?

  5. #5
    ShadeRF is offline Novice
    Windows 7 64bit Access 2010 32bit
    Join Date
    May 2011
    Posts
    24
    OpenQuery
    QueryName RetailUpdateQuerySS
    View Datasheet
    Data Mode Edit

    OpenQuery
    QueryName PricingQuerySS
    View Datasheet
    Data Mode Edit

    OpenReport
    Report Name PricingReportSSDGB
    View Report
    Window Mode Normal

    OpenReport
    Report Name PricingReportSS
    View Report
    Window Mode Normal

  6. #6
    hertfordkc is offline 18 year novice
    Windows XP Access 2007
    Join Date
    Mar 2011
    Posts
    481

    Your last response has me scratching my head.

    Have you made some choice prior to running the macro that sets conditions on one of the queries which will ultimately determine "BrandX", "BrandY" or something else? But you don't know the result until the query is run?
    And why two queries? if the decision is based on only one of the queries? Should you have combined the queries into one?
    Your summary of the macro didn't give any indication of testing for conditions in either query??
    I try to help with the problem presented, i.e. making a choice on which report to run, but suddenly I find myself asking "Why are you doing things this way?"
    For example, you could have a form (maybe hidden) that is based on the query which provides the decision making info, which could then select which report to run.


    Thread: Choosing Report Reply to Thread

  7. #7
    ShadeRF is offline Novice
    Windows 7 64bit Access 2010 32bit
    Join Date
    May 2011
    Posts
    24
    Initially there is a form and the user selects the Brand and inputs a price. Once this is done they click a Run button. The first query updates a Price field for the corresponding brand on the table, and the 2nd Query runs a series of formulas for that Brand. Based on the brand though I want a different report to show. They contain the same data from the query but the reports are formatted differently.

  8. #8
    hertfordkc is offline 18 year novice
    Windows XP Access 2007
    Join Date
    Mar 2011
    Posts
    481

    Makes more sense.

    Quote Originally Posted by ShadeRF View Post
    Initially there is a form and the user selects the Brand and inputs a price. Once this is done they click a Run button. The first query updates a Price field for the corresponding brand on the table, and the 2nd Query runs a series of formulas for that Brand. Based on the brand though I want a different report to show. They contain the same data from the query but the reports are formatted differently.
    __________________________________________________ _______________________

    From our earlier posts, I conclude that the once the user selects the Brand, you effectively know which report to run. Therefore, the form could at that point run one of two macros. Both macros would run the queries, but one macro would run report A and the other Macro would run report B. There are other ways to effect this, but this is the simplest IMHO.

  9. #9
    ShadeRF is offline Novice
    Windows 7 64bit Access 2010 32bit
    Join Date
    May 2011
    Posts
    24
    Would I do that in VBA? Something like IIF Brand LIKE "BRANDX*", Macro1, Macro2
    ?

  10. #10
    hertfordkc is offline 18 year novice
    Windows XP Access 2007
    Join Date
    Mar 2011
    Posts
    481

    Right on!

    Quote Originally Posted by ShadeRF View Post
    Would I do that in VBA? Something like IIF Brand LIKE "BRANDX*", Macro1, Macro2
    ?
    Based on your responses, I don't see any reason why you shouldn't have the Brand onClick event trigger the selection.

  11. #11
    ShadeRF is offline Novice
    Windows 7 64bit Access 2010 32bit
    Join Date
    May 2011
    Posts
    24
    I don't think I quite follow...

  12. #12
    ShadeRF is offline Novice
    Windows 7 64bit Access 2010 32bit
    Join Date
    May 2011
    Posts
    24
    I tried doing it this way onclick event procedure but I get a syntax error.

    IIf (([BRAND]) Like "BRANDX*") Or ([BRAND] Like "BRANDY*"), DoCmd.RunMacro PricingMacro1, DoCmd.RunMacro PricingMacro2)

  13. #13
    hertfordkc is offline 18 year novice
    Windows XP Access 2007
    Join Date
    Mar 2011
    Posts
    481

    Can you use VBA to handle the event?

    Quote Originally Posted by ShadeRF View Post
    I tried doing it this way onclick event procedure but I get a syntax error.

    IIf (([BRAND]) Like "BRANDX*") Or ([BRAND] Like "BRANDY*"), DoCmd.RunMacro PricingMacro1, DoCmd.RunMacro PricingMacro2)
    I don't think you can use DoCmd in the Expression Builder. And you'll probably need to do the a string comparison instead of using "Like".
    IIF is a function and returns a result, so using it in the expression builder is problematic.
    Suggest you go the OnClick property field, empty it and then click on the ellipsis (...) and select code builder. The Sub procedure will appear and you can do the necessary comparisons and DoCmd in there.

Please reply to this thread with any new information or opinions.

Similar Threads

  1. Replies: 1
    Last Post: 11-13-2011, 08:01 AM
  2. Choosing values of a field with drop-down menu.
    By kikonas in forum Database Design
    Replies: 4
    Last Post: 10-27-2011, 08:12 AM
  3. help in choosing from list
    By Nokia N93 in forum Programming
    Replies: 4
    Last Post: 11-30-2010, 07:29 AM
  4. Replies: 1
    Last Post: 11-26-2010, 05:22 AM
  5. Union Query (choosing between two fields)
    By naveehgreen in forum Programming
    Replies: 1
    Last Post: 06-17-2010, 03:24 PM

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts
  •  
Other Forums: Microsoft Office Forums