Results 1 to 4 of 4
  1. #1
    P5C768 is offline Advanced Beginner
    Windows XP Access 2003
    Join Date
    Aug 2009
    Location
    Denver, CO
    Posts
    95

    Difference between using Query based Report and Where Condition in OpenReport

    I was just wondering what the difference between using a report based on a query, where one field in the query has a parameter as a criteria, and the where condition in docmd.openreport is?

    For example, I wanted to create a receipt type report that would would open based on a transaction number. So I created a query that prompts for transaction number and then based a report on that query.

    Now I am trying to get a button to perform some code (which I have already tested and is working) and open the report based on the transactions number. I would have thought I would need VBA to fill in the transaction number, but I can't get that syntax correct, and adding a where condition doesn't seem to work either.

    Here is a sample of my syntax:

    MsgBox "Would you like to print a receipt?", vbYesNo,


    If vbYes Then DoCmd.OpenReport "Check_Out_Receipt_rpt", acViewPreview, , NextTransactionNum
    ElseIf vbNo Then
    MsgBox "Receipt will not be printed"
    End If

    Where NextTransactionNum is a number that is populated via prior code my taking the max of the numbers in a particular field in a table and adding 1.

    Thanks in advance for any help provided!

  2. #2
    weekend00 is offline I may not be right
    Windows XP Access 2003
    Join Date
    Aug 2010
    Posts
    1,295
    the code should be:

    If vbYes Then DoCmd.OpenReport "Check_Out_Receipt_rpt", acViewPreview, , "[transaction number]='" & NextTransactionNum &"'"

    Please set the filter on in the report in design view.

  3. #3
    P5C768 is offline Advanced Beginner
    Windows XP Access 2003
    Join Date
    Aug 2009
    Location
    Denver, CO
    Posts
    95
    I assume I need to take out the parameter from my query as well, right? I also get a "data type mismatch in criterion expression error." Would the syntax be different given that the [transaction number] is a number, not text?

  4. #4
    weekend00 is offline I may not be right
    Windows XP Access 2003
    Join Date
    Aug 2010
    Posts
    1,295
    if it is a number, don't need the ('):
    If vbYes Then DoCmd.OpenReport "Check_Out_Receipt_rpt", acViewPreview, , "[transaction number]=" & NextTransactionNum

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

Similar Threads

  1. Replies: 1
    Last Post: 11-04-2010, 12:57 PM
  2. DoCmd OpenReport ... where condition with a Like
    By Grooz13 in forum Programming
    Replies: 4
    Last Post: 08-31-2010, 09:04 AM
  3. Replies: 5
    Last Post: 06-19-2010, 07:55 PM
  4. Update 2 fields based on where condition.
    By Confused in forum Access
    Replies: 2
    Last Post: 11-19-2009, 05:21 PM
  5. Highlighting Report Data Based on a Condition
    By KramerJ in forum Reports
    Replies: 1
    Last Post: 05-29-2009, 10:27 AM

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