Page 1 of 3 123 LastLast
Results 1 to 15 of 41
  1. #1
    Join Date
    Dec 2007
    Posts
    70

    Unanswered: Quick way to copy reports?

    Hi,

    Is there a quick way to copy reports?

    I have to make quite a few reports and they all have the same lay out using the same fields, but unfortunately they are all to be based on different queries.

    Is there a quick way to copy all the reports but change the query they are based on? So I don't have to create them all individually from scratch?

    I tried to copy and paste the reports and then change the query but couldn't work out how to do this?

    Cheers,

    OB1

  2. #2
    Join Date
    Feb 2004
    Location
    One Flump in One Place
    Posts
    14,912
    So - the report is identical but the data populating the text boxes comes from different sources?

    Yes- the way I do this is use the OpenArgs parameter when calling a report - this allows you to pass strings of text. On the OnOpen event of the report, query this parameter and use the information you pass to decide what SQL you use to set the Me.RecordSource property.

    HTH

  3. #3
    Join Date
    Feb 2004
    Location
    One Flump in One Place
    Posts
    14,912
    BTW - this means you maintain a single report. A bit like the principle of code reuse, but applied to something more tangible.

  4. #4
    Join Date
    Dec 2007
    Posts
    70
    Hi,

    Not sure I follow? Would the report have to be based on just one of the queries?

    Sorry quite new to Access VB.

    OB1

  5. #5
    Join Date
    Feb 2004
    Location
    One Flump in One Place
    Posts
    14,912
    Ok - skipping the technical bit - here is the concept.

    You have one single report bound to NO query.
    Each time the report opens it automagically uses data from the query you want it to use.

    Does that sound like what you want? One report, one format, different data.

  6. #6
    Join Date
    Dec 2007
    Posts
    70
    That sounds exactly like what I need as I already have all the queries ready for use. So how is it done?

    Cheers,

    OB1

  7. #7
    Join Date
    Feb 2004
    Location
    One Flump in One Place
    Posts
    14,912
    Ok
    Srep #1 - backup your Access file (you do this regularly right?) so you can roll back
    Step #2 - edit the DoCmd.OpenReport .... code that opens the report and add a string for the seventh parameter. Make this what you like.
    Step #3 - create an OnOpen event for your report. In the event type:
    Code:
    Debug.Print Me.OpenArgs
    Check the Immediate Window and report back what it says.

    If you struggle with any of the above, check Help and Google to see if you can figure out what the step is.

  8. #8
    Join Date
    Dec 2007
    Posts
    70
    Quote Originally Posted by pootle flump
    Step #3 - create an OnOpen event for your report. In the event type:
    Code:
    Debug.Print Me.OpenArgs
    Hi, Just a quick question to the above code. If i want the report previewed and not printed do I replace the word 'print' with 'preview'?

  9. #9
    Join Date
    Feb 2004
    Location
    One Flump in One Place
    Posts
    14,912
    Nope - I would look up debugging (try Google) to get some grounding on what is going on. Debug.Print .... means print text strings to the Debugging window (AKA in VB\ VBA the Immediate Window).

    This has nothing to do with what will happen in the final report. All we want to do now is confirm that you are able to pass strings to the report and, correspondingly, receive them in the report. Once we have confirmed that we can move on to the next stage.

  10. #10
    Join Date
    Dec 2007
    Posts
    70
    Ok, well I have this and I've been doing a bit of looking around but can't find anything about the 'seventh parameter'? This is the code I've got but it wont let me set up the seventh parameter!

    [Code]
    Dim stDocName As String

    stDocName = "ZV_ALL_DATE"
    DoCmd.OpenReport stDocName, acPreview
    [end code]

    how do I add string for seventh patameter? Everything else in 3 steps are done.

    OB1

  11. #11
    Join Date
    Jun 2002
    Location
    Mpls/St.Paul area
    Posts
    303
    Mr. flump is suggesting that when you open the report, the code looks like this. (Perhaps this code is on a form where the user clicks a button to open the report)

    DoCmd.OpenReport "MyReport", acViewPreview, , , , "My arguments"

    Then when the report opens, the code behind the report has something to do with the argument.

    Private Sub Report_Open(Cancel As Integer)
    ' now use me.OpenArgs to filter on, or set the RecordSource
    End Sub

    To learn more on this lookup OpenArgs Property in Access help
    John
    This is the day the Lord has made, I will rejoice and be glad in it.

  12. #12
    Join Date
    Jun 2002
    Location
    Mpls/St.Paul area
    Posts
    303
    I agree with Mr. Flump about using one report.

    Another way to use one report mulitple ways is to change the Wherecondition. This is the fourth parameter in the docmd.openreport call.

    DoCmd.OpenReport "MyReport", acViewPreview,,"Company Name = 'ABC'"
    DoCmd.OpenReport "MyReport", acViewPreview,,"Company Name = 'NBC'"
    DoCmd.OpenReport "MyReport", acViewPreview,,"Company Name = 'Fox'"
    DoCmd.OpenReport "MyReport", acViewPreview,,"Weight > 300"

    Sample: If on your form, you have a text box next to a report button, your can use the user input. For example Show report by state: and you have a combobox to pick the state call cboState.

    DoCmd.OpenReport "MyReport", acViewPreview,,"State='" & Me.cboState & "'"

    note the proper use of parentheses.

  13. #13
    Join Date
    Dec 2007
    Posts
    70
    Here's my 2 codes, 1 to open report and other onopen of report, respectively.

    [code]
    Dim stDocName As String

    stDocName = "ZV_ALL_DATE"
    DoCmd.OpenReport stDocName, acPreview, , , , , "Works"
    [end code]

    [code]
    Debug.Print Me.OpenArgs
    [end code]

    Comes up with Compile error: Wrong number of arguments or invalid property assignments.
    Have I made a mistake?

  14. #14
    Join Date
    Feb 2004
    Location
    One Flump in One Place
    Posts
    14,912
    My mistake - 6th argument

    Seriously though - when you hit a problem, try double checking in help. If you did try and missed this then ignore but you'll learn a hell lot by working problems through. Note that the error gave you a good clue "...Wrong number of arguments...."

  15. #15
    Join Date
    Dec 2007
    Posts
    70
    Ok,
    when I put this in it works

    Code:
    Dim stDocName As String
    
        stDocName = "ZV_ALL_DATE"
        DoCmd.OpenReport stDocName, acPreview, , "Works"
    (thanks Pootle Flump)

    but now on the second code:

    Code:
    Private Sub Report_Open(Cancel As Integer)
    
        Debug.Print Me.OpenArgs
        
    End Sub
    it comes up with 'Method or Data member not found'?

    I think this is where I'm ment to be at with your three steps Pootle Flump?
    OB1

Posting Permissions

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