Solved

OpenArgs opening a report

Posted on 2008-10-31
25
687 Views
Last Modified: 2013-11-28
OpenArgs

I have a form that I am calling a report to open and print in pdf format. that is working. It is naming the report automatically also.

The report is 25 pages long but each page is based on a group. I want to print each page into a separate pdf fiel and name based on the group.

If I make a table  based on the groupings and then open the report with OpenArgs to just open each group and then have them print  how do I go about calling the OpenArgs?
0
Comment
Question by:Pdeters
[X]
Welcome to Experts Exchange

Add your voice to the tech community where 5M+ people just like you are talking about what matters.

  • Help others & share knowledge
  • Earn cash & points
  • Learn & ask questions
  • 14
  • 9
  • 2
25 Comments
 

Author Comment

by:Pdeters
ID: 22854048
How do I define OpenArgs
0
 
LVL 74

Expert Comment

by:Jeffrey Coachman
ID: 22854480
Do you HAVE to use open args?

Suppose there is another way?
0
 
LVL 58
ID: 22856547

  When you use the OpenReport method, the OpenArgs argument is the last one:

expression.OpenReport(ReportName, View, FilterName, WhereCondition, WindowMode, OpenArgs)

  You can pass any string value you want in there (actually I believe it's a variant, but I always pass a string).  if your going to pass multiple parameters, you need to delimit them in some way (I use a semi-colon).

  Then in the report, your refer to the OpenArgs property to get the value passed:

  strArgument = Me.OpenArgs

  What you do with it after that point is up to you.  However as Jeff was suggesting, there seems to be a better approach to this.

  What you can do is use the filter or Where argument on the OpenReport method and call the OpenReport once for each group.  That way, none of your report logic will change and you still can call the report and have it print all groups if you want.

JimD.
0
Instantly Create Instructional Tutorials

Contextual Guidance at the moment of need helps your employees adopt to new software or processes instantly. Boost knowledge retention and employee engagement step-by-step with one easy solution.

 

Author Comment

by:Pdeters
ID: 22856733
I don't have to use OpenArgs - just need to have this automated some how

Ok - So if I was going to call/filter the report for each group how would I do that? Also depending on what I filter is what the report is called - it is pulling from a field in the report

0
 
LVL 58
ID: 22856828

  Well you can either pass a query name in the filter argument to have the report filtered or provide a WHERE clause without the word WHERE in the WHERE argument of the OpenReport.

  So you'd do a loop in the calling code based on your group table and do something like:

  Do while not rst.EOF
    strWHERE = "[<myGroupIDField>] = " & rst![<myGroupIDFieldName>]
    DoCmd.OpenReport "<myReportName>", acViewNormal, , strWHERE
  Loop

 getting one report (and file) for each group.

JimD.
0
 

Author Comment

by:Pdeters
ID: 22856919
I will try that today - it sounds a lot easier.

How does it tell it to pull from what table/query - should I have the form based on that table/query?

0
 
LVL 58
ID: 22857030
<<How does it tell it to pull from what table/query - should I have the form based on that table/query? >>

  You mean the group?  I'd just open a recordset for the loop.

  I fthe report, just leave it the way it is now.  The WHERE clause you specify will get tacked on.

JimD.
0
 

Author Comment

by:Pdeters
ID: 22857455
When you say recordset for the loop - how do I open that up?
0
 
LVL 58
ID: 22859184
Sorry.  Your experience level said intermediate, so I thought it would have been something you would have done in the past.  This is the DAO method of opening a recordset:

  Dim db as DAO.Database
  Dim rst as DAO.Recordset

  Set db = Currentdb()
  Set rst = db.Openrecordset("<table or query name or a SQL statement here>")

  Do while not rst.EOF
    strWHERE = "[<myGroupIDField>] = " & rst![<myGroupIDFieldName>]
    DoCmd.OpenReport "<myReportName>", acViewNormal, , strWHERE
    rst.movenext
  Loop

  rst.close
  set rst = nothing
  set db = nothing

  anything that is in <> you need to replace with an actual value along with the <>

JimD.
0
 
LVL 74

Expert Comment

by:Jeffrey Coachman
ID: 22860168
Pdeters,

I seems that Jim has got this covered.

"Do you HAVE to use open args?"
"Suppose there is another way?"

The reason why I posted this is because all to many times a pereson will "Tell Us" how they want the problem solved.
Instead of simply asking: "How do I do this"?

For example you specifically stated: "how do I go about calling the OpenArgs?"
This hamstrings us into only considering Open Args (Even though there might be another way)

Or an asker will ask: "How do I use DAO to delete a record"
...When the real question should be: "Given these conditions, what is the best way to delete a record from a table"

Just FYI.

;-)

JeffCoachman
0
 

Author Comment

by:Pdeters
ID: 22867555
when I use this  I am getting "Enter Parameter Value" listing this fields name for each record in the recordset instead of putting it in as the header of the group. I then get each report printed out will all the records.

& rst![<myGroupIDFieldName>]


0
 
LVL 58
ID: 22868413
If you get prompted for a parameter, that means that Access doesn't knwo what your referring to.  Usually a mis-spelling.  But in this case, it may be the statement.  Is your GroupID a text field?  If so, the statement needs to be:

    strWHERE = "[<myGroupIDField>] = " & chr$(34) & rst![<myGroupIDFieldName>] & chr$(34)

  So there will be quotes around it.  Again, you must replace everything enclosed with <> with the actual values in your app.  For example, if your GroupID Field in the report was GroupID and in the recordset as well, then the statement would look like this:

    strWHERE = "[GroupID] = " & rst![GroupID]

   or this if it was a text field:

     strWHERE = "[GroupID] = " & chr$(34) & rst![GroupID]  & chr$(34)

JimD.
0
 

Author Comment

by:Pdeters
ID: 22869645

  I got this to work - used
strWHERE = "[GroupID] = " & chr$(34) & rst![GroupID]  & chr$(34)
As my field is a text

It prints each group as a separate file but I need it to go to pdf format not the printer.

"I have a form that I am calling a report to open and print in pdf format. that is working. It is naming the report automatically also."

This is what I was using to do the above before and am not able to work the strWhere into it without havng it print all pages and then it make 1 pdf file with everything it.

I have this on a command button to run the report and name it in pdf. I want to be able to print each on in a separate field (pdf)

      Dim stDocName As String
      Dim stOutputName As String
   
      stDocName = "rpt1"
      stOutputName = DLookup("GroupID", "qry1", True)
   
     stOutputName = stOutputName & Format(Date, "yyyymmdd")
      Call ConvertReportToPDF(stDocName, vbNullString, stOutputName & ".PDF", False)
0
 
LVL 58
ID: 22869923
What's in ConvertReportToPDF()?

 There's got to be a DoCmd.OpenReport somewhere.  You could not "print" the report otherwise.

JimD.
0
 

Author Comment

by:Pdeters
ID: 22870003
I am sorry - I am confusing here and I need to be more clear.

Iam running a function that is printing to a pdf format.

This is the function I am using

http://www.experts-exchange.com/Microsoft/Development/MS_Access/Access_Coding-Macros/Q_23851846.html



0
 

Author Comment

by:Pdeters
ID: 22870515
I need to put the code you have shown me into the module don't I.

0
 
LVL 58

Accepted Solution

by:
Jim Dettman (Microsoft MVP/ EE MVE) earned 500 total points
ID: 22870952
<<I need to put the code you have shown me into the module don't I.>>

 Actually, no.  Stephan's code is using the output to method to get the report to snapshot form and then converts to PDF.  So there is no point where a OpenReport is called.

  Which means an alternative approach; the report will have to handle it.  Since this is the output to method, you can't use OpenArgs either, so you'll need to pass the Group ID in a variable.

  Then in the reports OnOpen event, you'll look at the variable and then set the reports Filter property.

  The loop I gave you would stay right where it is, but you'd set the variable, then call   Call ConvertReportToPDF() to get the report generated.

  Have I given you enough to go on or would you like me to go into more detail?

JimD.
0
 

Author Comment

by:Pdeters
ID: 22871129
I think I have it. Let me give it a try. If  I need more detail I will let you know but I want to give a try first
0
 

Author Comment

by:Pdeters
ID: 22871274
Ok - I guess I do need more help.

Where do I set the variable to send it to the report
0
 

Author Comment

by:Pdeters
ID: 22871335
I put the Filter in the report to "YEs"
and the Filter on [GroupID]
0
 

Author Comment

by:Pdeters
ID: 22875235
<<  The loop I gave you would stay right where it is, but you'd set the variable, then call   Call ConvertReportToPDF() to get the report generated.>>

How do I get the variable to pass and still have the report generate the name
This is what I had used but jsut got all the pages.
Would i put something like this in the report

Dim stDocName As String
      Dim stOutputName As String
   
      stDocName = "rpt1"
      stOutputName = DLookup("GroupID", "qry1", True)
   
     stOutputName = stOutputName & Format(Date, "yyyymmdd")
      Call ConvertReportToPDF(stDocName, vbNullString, stOutputName & ".PDF", False)

0
 
LVL 58
ID: 22885100

  Sorry I wasn't around yesterday.  Were you able to finish this up or do we need to keep working on it.

JimD.
0
 

Author Comment

by:Pdeters
ID: 22885159
Not a problem. I got it figured out.  Thanks so much for the help it is really appreciated!
0
 
LVL 58
ID: 22885168
<<Not a problem. I got it figured out.  Thanks so much for the help it is really appreciated!>>

 Terrific!  Kudos for sticking with it and getting it working.  We beat around the bush there a bit, but hopefully you learned a few extra things becasue of that.

Have a good day,
JimD.
0
 

Author Comment

by:Pdeters
ID: 22891390
I did and thanks again
0

Featured Post

Technology Partners: We Want Your Opinion!

We value your feedback.

Take our survey and automatically be enter to win anyone of the following:
Yeti Cooler, Amazon eGift Card, and Movie eGift Card!

Question has a verified solution.

If you are experiencing a similar issue, please ask a related question

Access custom database properties are useful for storing miscellaneous bits of information in a format that persists through database closing and reopening.  This article shows how to create and use them.
You need to know the location of the Office templates folder, so that when you create new templates, they are saved to that location, and thus are available for selection when creating new documents.  The steps to find the Templates folder path are …
Using Microsoft Access, learn some simple rules for how to construct tables in a relational database. Split up all multi-value fields into single values: Split up fields that belong to other things into separate tables: Make sure that all record…
In Microsoft Access, learn different ways of passing a string value within a string argument. Also learn what a “Type Mis-match” error is about.

726 members asked questions and received personalized solutions in the past 7 days.

Join the community of 500,000 technology professionals and ask your questions.

Join & Ask a Question