Solved

OpenArgs opening a report

Posted on 2008-10-31
25
669 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
  • 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 57
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
 

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 57
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 57
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 57
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 57
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
How to run any project with ease

Manage projects of all sizes how you want. Great for personal to-do lists, project milestones, team priorities and launch plans.
- Combine task lists, docs, spreadsheets, and chat in one
- View and edit from mobile/offline
- Cut down on emails

 

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 57
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 57

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 57
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 57
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

IT, Stop Being Called Into Every Meeting

Highfive is so simple that setting up every meeting room takes just minutes and every employee will be able to start or join a call from any room with ease. Never be called into a meeting just to get it started again. This is how video conferencing should work!

Join & Write a Comment

Most if not all databases provide tools to filter data; even simple mail-merge programs might offer basic filtering capabilities. This is so important that, although Access has many built-in features to help the user in this task, developers often n…
It took me quite some time to sort out all the different properties of combo and list boxes available from Visual Basic at run-time. Not that the documentation is lacking: the help pages are quite thorough and well written. The problem was rather wh…
Familiarize people with the process of utilizing SQL Server views from within Microsoft Access. Microsoft Access is a very powerful client/server development tool. One of the SQL Server objects that you can interact with from within Microsoft Access…
With Microsoft Access, learn how to specify relationships between tables and set various options on the relationship. Add the tables: Create the relationship: Decide if you’re going to set referential integrity: Decide if you want cascade upda…

759 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

Need Help in Real-Time?

Connect with top rated Experts

20 Experts available now in Live!

Get 1:1 Help Now