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!

print current record (day) as report

Status
Not open for further replies.

brh01

Technical User
Feb 23, 2003
103
Hi i want to add a button to my form that will print a report of the the current record. 1 record = 1 day in db.

how do I set this up so that when the button is pressed the current record will be previewed and then printed with a header.

right now the print button wants to print all records as 1 report and the only header is at the top of the first page.

I've done a search thru the site and the only examples i can find will not work. thank you

Brian
 
Say your form is called frmForm.
And you have a unique RecordID on that form, called RecordID.
And in your report, the unique RecordID may also be called RecordID, but for this example I will call it ReportRecordID.

You will have to tweak the code and fill in your own object names.

in the OnClick event of your button, you would put:

If you unique Record ID is a number:
Code:
docmd.OpenReport "ReportName",acviewpreview,,"ReportRecordID = " & me.RecordID

If you unique Record ID is text:
Code:
docmd.OpenReport "ReportName",acviewpreview,,"ReportRecordID = '" & me.RecordID & "'"
(notice the single and double quotes)

Hope this helps--g

 
On Click event:

DoCmd.OpenReport "reportName", acViewPreview, , "PrimaryID=" & PrimaryID
 
hkaing...run time error...
extra ) in query expression '(primaryID)'

DoCmd.OpenReport "rprtmain", acViewPreview, , "PrimaryID=" & PrimaryID


Brian
 
gingerR...compile error...method or data not found.

Brian
 
funny there are different errors as our code is exactly the same?

is your ID text or number?

what is the name of the ID field in the Report's recordsource?

what is the name of the control that holds the ID on the form?
 
I'm sure its something i'm doing wrong because I've taken this same code out of quite a few posts in the last few days and can't figure it out. thanks for the assistance.

# 1- number

#2- tblsavedinfo is the table in the recordsource box. "id" is the pk

#3- please re phrase question

Brian
 
DoCmd.OpenReport "rprtmain", acViewPreview, , "ID=" & me.ID

#3-what is the name, if any, of the text box where you have the ID on the form? Is it "ID"? in the code I just wrote, I'm assuming it is.
 
my form and my report, both have the same recordsource. when i press the button i get an error saying the recordsource is being used by the form.

Brian
 
what's the exact message?

try making your first line in the OnClick be

DoCmd.DoMenuItem acFormBar, acRecordsMenu, acSaveRecord, , acMenuVer70

to save the record. maybe that's the problem--are you in the middle of data entry?
 
I press the button when I'm done the data entry, yes.

I added the code and this error still comes up...

the db engine could not lock the table tblsavedinfo because it is already in use by another person or process

Brian
 
in your form's design, view the properties. what do you have Record Locking set to? Usually it should be Edited Record. Do you have it as ALL RECORDS?
 
hi, it was set to no locks. i changed it to edited records. but still get the same error

Brian
 
hmmm....this should be simple.

ok so paste here your code in the Button's OnClick event.

so--just confirming--if you take out the WHERE statement from your code (the bit about "ID = " & me.ID) the button works? the report comes up, but with ALL records?
 
DoCmd.OpenReport "rprtmain", acViewPreview, ,.... syntax error

code in the Button's OnClick event....w/ where stmnt removed..

Private Sub Command100_Click()
DoCmd.DoMenuItem acFormBar, acRecordsMenu, acSaveRecord, , acMenuVer70

DoCmd.OpenReport "rprtmain", acViewPreview, ,
End Sub

Brian
 
take out the commas...

DoCmd.OpenReport "rprtmain", acViewPreview
 
error... cannot lock table etc. etc. (same as above.)

something i've noticed...if i by pass the form, open the report in preview, the latest record is now what shows in the window w/ a header as it should be. however if i select the multipage view, i see continuous reports...

record 63, 1, 2, 3, 4...

Brian
 
what's the recordsource of the report?

honestly...this shouldn't be this difficult!!
 
sorry but this is just making me crazy.

i know it sounds horrible, but in order to troubleshoot this, could you say create a brand new report, base it on your table, put a few fields on it, save it as TestReport. Open it. does it work (shows all records)?

create a brand new form, based on your table, save it as TestForm. save it. Open it. does it work (shows all records as you navigate thru it?)

on the form, put a button. cancel out when the wizard comes up.

paste into the button's OnClick event:

docmd.openreport "TestReport",acviewpreview

open the form. test the button. does it work (shows all records?)

go back into design mode of the form, into the OnClick of the button. paste in this:

docmd.openreport "TestReport",acviewPreview,,"ID = " & me.id

does it work?

sorry for the mess, but really, it shouldn't be this big of a deal...
 
Status
Not open for further replies.

Part and Inventory Search

Sponsor

Back
Top