By using this site, you agree to our updated Privacy Policy and our Terms of Use. Manage your Cookies Settings.
429,564 Members | 804 Online
Bytes IT Community
+ Ask a Question
Need help? Post your question and get tips & solutions from a community of 429,564 IT Pros & Developers. It's quick & easy.

Print report based on current record

P: n/a
I am attempting to use the following code to print a report based on
the current record in the form. Users bring up the record with a
parameter box and then can make changes to the sub-form on the main
form (main form is locked). I use this same code for another
form/report and it works. The only difference is the parameter. The
one that works opens to all records and then the user uses the filter
by form. I don't want them to do that on this form. Can anyone help?
Thanks - Karen

Private Sub Command91_Click()
On Error GoTo Err_Command91_Click

Dim strWhere As String
If Me.FilterOn Then
strWhere = Me.Filter
End If
DoCmd.OpenReport "rptJobRecord-Auto", acViewPreview, , strWhere

Dim stDocName As String

stDocName = "rptJobRecord-Auto"
DoCmd.OpenReport stDocName, acPreview

Exit_Command91_Click:
Exit Sub

Err_Command91_Click:
MsgBox Err.DESCRIPTION
Resume Exit_Command91_Click

End Sub

Nov 13 '05 #1
Share this Question
Share on Google+
2 Replies


P: n/a
Dim strWhere As String
If Me.FilterOn Then
strWhere = Me.Filter
End If
DoCmd.OpenReport "rptJobRecord-Auto", acViewPreview, , strWhere

Your strWhere should be something like....

[PrimaryKeyOfTable] = Me.PrimaryKeyFieldControlOnForm

Oh, and it should be delimited properly
Text - use single quotes.
Dates - use # signs
numbers - use nothing.

Something like
Const cQUOTE = "'"
strWhere = "[IDNo]=" & cQuote & Me.TextIDField & cQUOTE

DoCmd.OpenReport "rptJobRecord-Auto", acPreview, strWhere

HTH

Nov 13 '05 #2

P: n/a
Access 97 HELP - Create a report displaying only the current record
selected.

Hello guys, This is how I did it.

1. Create your report. The report does not need to be based on a
query or have a datasource.

2. Drop unbound text boxes into the reports to hold your fields. Type
the names of the fields in your form into the report text boxes in the
following format:
=[Forms]![nameOfYourFormGoes Here]!nameOfFieldGoes Here
This is telling the report to use the currently selected record of the
specified form as the source for the specified field. Obviously for
the report to work the form must be open and a record selected.

3. Save your report. Go into Macros section, and create a new macro.
Set the first action for your Macro to 'OutputTo'. Set object type to
'Report', set object name to the name of your report, set output
format to Rich Text Format, and set the other fields here according to
your preference. Save the macro.

4. Open your form in design view and drop a command button into an
appropriate place. In the properties for your button, under 'on click'
select your newly create macro.

5. Then, go into the form properties and make sure the Source is blank
instead of referring to the table.

Thank you Boiled Egg and Larry Daugherty!

Nov 13 '05 #3

This discussion thread is closed

Replies have been disabled for this discussion.