Tek-Tips is the largest IT community on the Internet today!

Members share and learn making Tek-Tips Forums the best source of peer-reviewed technical information on the Internet!

  • Congratulations derfloh on being selected by the Tek-Tips community for having the most helpful posts in the forums last week. Way to Go!

Calling the same report with different query data several times? 1

Status
Not open for further replies.

delmorpha

Programmer
Jun 15, 2007
3
GB
Hi, Im trying to call the same report several times in VB using a global variable to control the initial query results and I can't seem to get it working - to be honest I'm a C coder not a VBA coder and am a bit of a n00b when it comes to Access and VB so I get a bit frustrated at the minute!

I have the following code that I have been testing linearly but eventually I want it to be recursive but thats a side issue as at the minute it does not want to close the form to move onto the next load

GBL_ClientID = "XXX"
On Error Resume Next
DoCmd.OpenReport "rptJobSheetBETA", acViewPreview
If Err = 2501 Then Err.Clear 'Else DoCmd.PrintOut
DoCmd.SelectObject acForm, "rptJobSheetBETA"
DoCmd.Close acForm, "rptJobSheetBETA"
DoEvents

GBL_ClientID = "YYY"
On Error Resume Next
DoCmd.OpenReport "rptJobSheetBETA", acViewPreview
If Err = 2501 Then Err.Clear 'Else DoCmd.PrintOut
DoCmd.SelectObject acForm, "rptJobSheetBETA"
DoCmd.Close acForm, "rptJobSheetBETA"
DoEvents

... etc etc

And so on. What currently happens is it loads the first job sheet and thats it - it should print the jobsheet then close the form, then reopen it with new data. I have multiple client IDs that the job sheets refer to but they all aren't necessarily done on a daily basis when the job sheets are created.

Could anyone shine some light on this problem at all? Am I making any sense? :)
 
are these reports or forms?

to automatically print a report, just use:
docmd.openreport reportName, acViewNormal

to close a report, use:
docmd.close acReport, reportName

--------------------
Procrastinate Now!
 
You're a superstar... thank you very much for pointing out the very stupid typo! Fully working now! :D

A by-product of this is why are there no variable controls for VB?! ;)
 
variable controls?

--------------------
Procrastinate Now!
 
Sorry, I mean like there where I've passed the SelectObject function a report not a form but used acForm instead of acReport.. I would expect that to produce an error/fall on its backside in C but VB is happy to ignore it. Better for stability but annoying when you make stupid mistakes and typos!
 
erm, it should give you a runtime error saying the form hasn't been found...

--------------------
Procrastinate Now!
 
but VB is happy to ignore it
You're the only culprit as you coded the following:
On Error Resume Next

Hope This Helps, PH.
FAQ219-2884
FAQ181-2886
 
Status
Not open for further replies.

Part and Inventory Search

Sponsor

Back
Top