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

Hey access! Print this page please!

Status
Not open for further replies.

katiekat

Technical User
Jun 6, 2000
300
US
I have a report that displays all of a company's Info on one page. I have this lovely Idea. I have forms that also display all sorts of information. I would like to have a button that either opens up the corresponding page in the report, or prints the actual page, all by itself. That would rule, but I think it might be a little too complicated for me. Is this something that is possible? I have looked into writing a macro, but the goto or findreccord things don't work for reports apparently. Can you all help??? =) [sig][/sig]
 
If I am understanding correctly, you want to print a single page of a report based off a record that is currently on focus in a form. The following code, placed in the OnClick procedure, will print off a single record.

Private Sub cmdPrintPO_Click()
Me.Refresh
Dim strRptName As String
Dim strWhere As String
strRptName = "nameofreport"
strWhere = "[PK]=" & Me!PK
DoCmd.OpenReport strRptName, acPrint, , strWhere
End Sub

where nameofreport is the name of the report that will be run, and PK is the name of your Primary Key field for the form.
acPrint will print directly, you can also use acPreview to get the print preview screen first.
the Me.Refresh is in there in case you add a record and try to print it before the record is actually written to the table.

Hope this is something close to what you want. [sig][/sig]
 
This is perfect, thank you! But it seems to be having trouble with the last line there, the docmd.openreport action thingie. It says, action required, and in the debug window, the last line is highlighted in yellow. You probably wont come back and read this, but it's worth a try. Thank you very much for your help!!!
 
Well, unless someone else can jump in with a solution, I can try to help. If you post the code you have for this and explain a little more about the report, I'll give it my best shot.
 
Thanks! You're the best! *:->*

here's what I have:
Code:
Private Sub Command46_Click()
 Me.Refresh
 Dim strrptname As String
 Dim strwhere As String
    strrptname = "Company Info Report"
    strwhere = "[Company ID]=" & Me![Company ID]
    CoCmd.OpenReport strrptname, acPreview, , strwhere

End Sub

The report is huge, if that makes a difference, I don't know if it does or not. It's not really that complicated, 2 subreports based on tables, the main body is based on 2 different querys.

I don't think I am naming some object right, I think that may be the problem.
 
Wiznane, is this just a typo or do you really have the last command as CoCmd.OpenReport? :)

Eradic8or x-)
 
ok, so obviously, there is something wrong with that. Please enlighten me. I really have very little clue as to what I am doing so help would be appreciated. thanks!
 
Yes, the CoCmd.OpenReport that you (I assume you cut n pasted your code), should be GoCmd.OpenReport, just a typo.
Also, in

strwhere = "[Company ID]=" & Me![Company ID]

instead put

strwhere = "[Company ID]=" & Me!Company ID

Though I don't know if it will work well with a space in there. I know sometimes VBA doesn't like the space, but maybe quotes around the second Company ID may make it work or renaming it to CompanyID.
 
Code:
Private Sub Command46_Click()
 Me.Refresh
 Dim strrptname As String
 Dim strwhere As String
    strrptname = "companyinforeport"
    strwhere = "[CompanyID]=" & Me!CompanyID
    GoCmd.OpenReport strrptname, acprint, , strwhere

End Sub

Ok, I went through and changed the name to companyid, and it still is having problems. :-( Still with the last line. Runtime 424, "object required". I can't figure it out. I went and changed the report name to get rid of the spaces, thinking maybe it didn't recognize it as an object, but it didn't like that either. Any ideas? Thank you sooooo much for your help!!!
 
The command is Docmd.Openreport. Not Gocmd.Openreport

Eradic8or.
Sorry for replying late.
 
heh heh, I typoed trying to correct a typo. What are the chances?
 
Status
Not open for further replies.

Part and Inventory Search

Sponsor

Back
Top