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 Mike Lewis on being selected by the Tek-Tips community for having the most helpful posts in the forums last week. Way to Go!

Form Checkbox If yes Print Associated Report

Status
Not open for further replies.

naturalsn

Technical User
Apr 26, 2007
68
GB
Good Morning

I am hoping someone might possibly assist

I have a very simple DB
1x Table
1x Form
4x Reports

In my table i have four yes/no fields that will indicate the required reports to print (with the specific record)

I have taken the four fields and placed them on the main form as the check boxes. This will be their first entry to the DB

At the end of the form i would like to print all the necessary reports that has been ticked by the user

i have tried the following the following code. by absolutely no luck.

Am i missing something..

Thank you very much in advance for any help


Code:
Private Sub cmdPrintReports_Click()

If Me.Recipient = True Then
DoCmd.print "rpt1RecipientCopy"
End If

If Me.Return = True Then
DoCmd.print "rpt2ReturnCopy
End If

If Me.File = True Then
DoCmd.Print "rpt3FileCopy
End If

If Me.Quality = True Then
DoCmd.Print "rpt4QualityReviewEnd"
End If
End Sub
 
Try this - it will print it to your default printer

Code:
DoCmd.OpenReport "rpt1RecipientCopy", acNormal

Take it Easy
Man with one chopstick go hungry
 
Hi Kiwiman
Thanks for you help...

No luck though

I now get an error

Object doesn't support this property or method (Error 438)

and on debug, goes to the first entry

If Me.Recipient = True Then etc etch

My code is now as follow

Code:
Private Sub cmdPrintReports_Click()

If Me.Recipient = True Then
DoCmd.OpenReport "rpt1RecipientCopy", acNormal
End If

If Me.Return = True Then
DoCmd.OpenReport "rpt2ReturnCopy", acNormal
End If

If Me.File = True Then
DoCmd.OpenReport "rpt3FileCopy", acNormal
End If

If Me.Quality = True Then
DoCmd.OpenReport "rpt4QualityReviewEnd", acNormal
End If
End Sub

[code/]
 
What about - where Me.recipient is the name of the relevant control on your form.

What version of access are your running?

Code:
If Me.recipient= -1 Then
    DoCmd.OpenReport "rpt1RecipientCopy", acNormal
Else
End If

You could try typing in the Docmd.openreport and see what parameters it comes up with...

Take it Easy
Man with one chopstick go hungry
 
AAa my apologies the error 438 is Nameing problemsss..ppprrff my apologies

There is another problem though.. It is now printing brilliantly. But for every report i click to print.
It prints every single record in the DB.

I added the "DocId = " & Me!DocID" to the code. to associate the Document ID am i currently working with
but still prints everything.

Any suggestions

Code:
If Me.DisRecipient = True Then
DoCmd.OpenReport "rpt1RecipientCopy", acNormal, , _
"DocId = " & Me!DocID
End If

If Me.DisReturn = True Then
DoCmd.OpenReport "rpt2ReturnCopy", acNormal, _
"DocId = " & Me!DocID
End If

If Me.DisFile = True Then
DoCmd.OpenReport "rpt3FileCopy", acNormal, _
"DocId = " & Me!DocID
End If

If Me.QualityReview = True Then
DoCmd.OpenReport "rpt4QualityReview", acNormal, _
"DocId = " & Me!DocID
End If
End Sub
 
Hi Kiwiman, Thanks for your help.

I am running 2003 sp3
 
In your query underlying the report, reference the field that relates to the current record on your form to id on your form

E.g.
I have a report that runs based on the Company I choose from combo box, so in the underlying query i have in the criteria field "[Forms]![frmOpenOrders]![cboDB]", so it only prints the report for that company.

Take it Easy
Man with one chopstick go hungry
 
you shouldn't need the DocId etc in the docmd syntax then

Take it Easy
Man with one chopstick go hungry
 
It does not like that...

Gives me an error, runtime 3464
Data Type Mismatch in criteria expression

I used "[Forms]![frmDocTransmittal]![docId]" under the docId Field

Removed extra docId syntax.

Wonder if that is not because of it being a checkbox and not a combo..


 
What does the docid represent? Do we have this field in your query that the report runs off?

Take it Easy
Man with one chopstick go hungry
 
Just the primary ID.

Yip, on the report but set visible to NO.
 
Naturasn- Kiwiman was refering to your form- is the docid on your form? You have three steps happening 1.The query that the report is built on 2.The Report 3.The button that runs the report(s). Work on each until that one step is working then move to the next. When one report is as you want including printing then add another until all four.
 
Hi Bubba

Yes Id is on the form.
The form is based on the Main table, Pretty strait forward.

I have done the steps individually as indicated.

Report works fine if i do a normal docmd.print with
Code:
DocId = " & Me!DocID
So it prints the current record i am working with.

So this as a test indicates that my id is available to the form and the report.

it is just now however when i am using the checkboxes, to tick the report i would like, that it prints. but prints every single record in the Databse.

So currently there are 5 records in my table.
so for every report I say print, it prints 5 instead of the one i am currently working with.

Thank you very much for the patience and help so far though..


 
Hi

Sorry - called away.

When you view the results of your query, how many records are returned.

If the query is linked to the current record of your form, it should only return the records relating to that id nothing else.

If you set you docid to visible, but set it also to disabled, then the control will show, but can not be selected. Does this help?

Take it Easy
Man with one chopstick go hungry
 
If this does not work what does?
DoCmd.OpenReport "rpt1RecipientCopy", acNormal, , _
"DocId = " & Me!DocID

Also have installed PHV's suggestion?
 
Hi bubba

yes just did the installation. no change

i just recently tested the following

Code:
DoCmd.DoMenuItem acFormBar, acRecordsMenu, 5, , acMenuVer70
If IsNull(Me!DocID) Then
MsgBox "Please select a valid record", _
vbOKOnly, "Error"
Exit Sub
End If
DoCmd.OpenReport "rpt1RecipientCopy", acNorma, _
"DocId = & me!DocId"
End Sub

Still prints out all the records


the Table has the DocId in it
The form is based on the table no query just recordsource select statement where DocId is in
Created Form all the field are in it.
Enter Details
And print the reports. from where current entry has been done.

I am missing something..



 
Howsit

Can you post the sql view of the query underlying the report, please.

We will get there me hopes...

Take it Easy
Man with one chopstick go hungry
 
Replace this:
DoCmd.OpenReport "rpt1RecipientCopy", acNorma, _
"DocId = & me!DocId"
with this:
DoCmd.OpenReport "rpt1RecipientCopy", acViewNormal, , "DocId = "& Me!DocId

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

Part and Inventory Search

Sponsor

Back
Top