C
Coleen
I posted this yesterday under the thread for "How can I print screen a
report?"
I tried your code Rick, but either get the error shown below, or when I add
the table name to the field name I get a box to enter the ID number in...
Here is the code that I am using:
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 = "[Test Vehicle As].Vehicle_ID = " &
Me.Test_Vehicle_As_Vehicle_ID
DoCmd.OpenReport "Vehicle Emission Control Information Report",
acViewPreview, , strWhere
End If
I tried using the same format for the ID on both sides but that gives me the
"|" error again, so, I'm at a loss...any suggestions? TIA,
Coleen
__________________________________________________
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
report?"
I tried your code Rick, but either get the error shown below, or when I add
the table name to the field name I get a box to enter the ID number in...
Here is the code that I am using:
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 = "[Test Vehicle As].Vehicle_ID = " &
Me.Test_Vehicle_As_Vehicle_ID
DoCmd.OpenReport "Vehicle Emission Control Information Report",
acViewPreview, , strWhere
End If
I tried using the same format for the ID on both sides but that gives me the
"|" error again, so, I'm at a loss...any suggestions? TIA,
Coleen
__________________________________________________
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