Did you change the Field Name "[ID]" in Rick's code to the corresponding
unique identifier of your record? The Control on the Form where the Field
[ID] is displayed should have a different name than the Field that is its
Control Source, to avoid confusion.
Larry Linson
Microsoft Access MVP
Hi Rick - thanks for answering this post - I am having the same issues. I
have created a report and have a button to preview it from the form - this
works great. My users do want the report to open to the record they have
just entered.
I tried your code and get and error that "Microsoft Access can't find the
field '|' referred to in your expression. I'm running the report off a query
not a table, will that make a difference?
I also tried a docmd.gotorecord, last, but could not get that to work
either...
TIA,
Coleen
"Rick B" <Anonymous> wrote in message
Forms are not designed to be printed. You should build a report and tie
that to a button. You can even use the form and "save it as a report" then
open it in design-view and clean it up. Below is some code to tie to the
button so that only the currently-displayed record is included on the
report.
If you really want to just print the screen. I believe pressing
CTRL+PRINT SCREEN will do so. I know that ALT+PRINT SCREEN will capture the
current window and place it in the clipboard.
Button to print specific record
Private Sub cmdPrint_Click()
Dim strWhere As String
If Me.Dirty Then 'Save any edits.
Me.Dirty = False
End If
If Me.NewRecord Then 'Check there is a record to print
MsgBox "Select a record to print"
Else
strWhere = "[ID] = " & Me.[ID]
DoCmd.OpenReport "MyReport", acViewPreview, , strWhere
End If
End Sub
Notes: If your primary key is a Text type field (not a Number type
field), you need extra quotes: strWhere = "[ID] = """ & Me.[ID] & """"
If you want the report to print without preview, replace acViewPreview
with acViewNormal.
See also:
http://allenbrowne.com/casu-15.html
--
Rick B
"I need immediate help!! Please" <I need immediate help!!
(e-mail address removed)> wrote in message
news:
[email protected]...