Pdeters
asked on
OpenArgs opening a report
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?
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?
Do you HAVE to use open args?
Suppose there is another way?
Suppose there is another way?
When you use the OpenReport method, the OpenArgs argument is the last one:
expression.OpenReport(Repo
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.
ASKER
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
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
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.
ASKER
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?
How does it tell it to pull from what table/query - should I have the form based on that table/query?
<<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.
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.
ASKER
When you say recordset for the loop - how do I open that up?
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.
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.
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
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
ASKER
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>]
& rst![<myGroupIDFieldName>]
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.
strWHERE = "[<myGroupIDField>] = " & chr$(34) & rst![<myGroupIDFieldName>]
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.
ASKER
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(stDocNa
What's in ConvertReportToPDF()?
There's got to be a DoCmd.OpenReport somewhere. You could not "print" the report otherwise.
JimD.
There's got to be a DoCmd.OpenReport somewhere. You could not "print" the report otherwise.
JimD.
ASKER
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
https://www.experts-exchange.com/questions/23851846/Printing-to-Adobe-from-Access.html
Iam running a function that is printing to a pdf format.
This is the function I am using
https://www.experts-exchange.com/questions/23851846/Printing-to-Adobe-from-Access.html
ASKER
I need to put the code you have shown me into the module don't I.
ASKER CERTIFIED SOLUTION
membership
This solution is only available to members.
To access this solution, you must be a member of Experts Exchange.
ASKER
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
ASKER
Ok - I guess I do need more help.
Where do I set the variable to send it to the report
Where do I set the variable to send it to the report
ASKER
I put the Filter in the report to "YEs"
and the Filter on [GroupID]
and the Filter on [GroupID]
ASKER
<< 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(stDocNa me, vbNullString, stOutputName & ".PDF", False)
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(stDocNa
Sorry I wasn't around yesterday. Were you able to finish this up or do we need to keep working on it.
JimD.
ASKER
Not a problem. I got it figured out. Thanks so much for the help it is really appreciated!
<<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.
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.
ASKER
I did and thanks again
ASKER