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 bkrike 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

Status
Not open for further replies.

lashwarj

IS-IT--Management
Nov 1, 2000
1,067
US
I have this code in a command button and for some reaosn it will not print the current record but insist on printing all records in my database, Question is how do I when on a form say 34 of 2390 print only record 34 with my report

Heres my code

strReportname = "Birth"
strCriteria = "[regno] = " & Me! [regno]
DoCmd.DoMenuItem acFormBar, acRecordsMenu, acSaveRecord, , acMenuVer70
DoCmd.OpenReport strReportName, acViewPreview, , strCriteria


 
Try putting the criteria in the actual query that is supplying the report it's data. To do this you would go into the design view of the query and in the criteria of [regno] place [Forms]![MyFormName]![regno]. That will make your query look at the regno control on your form and limit the query to only that record. I find this method easier to follow and understand than the LinkCriteria method

HTH Joe Miller
joe.miller@flotech.net
 
I have no query running this the report is based on a table. I have gotten this to work before but i cant recall how
 
try this

strReportname = "Birth"
DoCmd.DoMenuItem acFormBar, acRecordsMenu, acSaveRecord, , acMenuVer70
strCriteria = "regno = " & Me!regno
DoCmd.OpenReport strReportName, acViewPreview, , strCriteria
 
It is not a good idea to base reports on tables. When you base reports on queries, Access can then take advantage of the indexes built into the database, resulting in faster returns in data retrieval. All you need to do, is make a new query that has all the fields from your table, set your options (if any are desired) and add the criteria. Once this is done, go into the report, go into the properties and set the RecordSource of the report to your query. You won't have to change anything else in your report if you follow these instructions. You'll get a faster report, and you'll get your criteria taken care of.
Joe Miller
joe.miller@flotech.net
 
Hi lashwarj-
The following code is an event procedure for a command button. The report is based on a table. It will print the record ([recordno] is the name of autonumber field in the table) on the screen at the time.


Dim stDocName As String

stDocName = "rptname"
DoCmd.DoMenuItem acFormBar, acRecordsMenu, acSaveRecord, , acMenuVer70

DoCmd.OpenReport "rptname", acViewPreview, , "[recordno] =" & [recordno]

Hope this helps!

Lynne




 
Status
Not open for further replies.

Part and Inventory Search

Sponsor

Back
Top