I had to remove a space in the Do.cmd line before strWhere
Yes, the document is in Print Preview mode when we go to
print.
Existing Code:
Private Sub Print_Preview_Work_Order_Click()
On Error GoTo Err_Print_Preview_Work_Order_Click
Dim stDocName As String
Dim strWhere As String
If Me.Dirty Then 'save any edits
Me.Dirty = False
End If
If Me.NewRecord Then
MsgBox "Select a record to view."
Else
stDocName = "Work Order Printout"
strWhere = "[ID] = " & Me.[ID]
DoCmd.OpenReport stDocName, acViewPreview, ,
strWhere
End If
Exit_Print_Preview_Work_Order_Click:
Exit Sub
Err_Print_Preview_Work_Order_Click:
MsgBox Err.Description
Resume Exit_Print_Preview_Work_Order_Click
End Sub
Private Sub Work_Order___BeforeUpdate(Cancel As Integer)
End Sub
-----Original Message-----
What space did you remove?
How does the line read now - the one that gives the
problem.
The only difference you need to get it to print instead
of preview, is to
replace
acViewPreview
with
acViewNormal
Is the preview already open when you attempt to print it?
--
Allen Browne - Microsoft MVP. Perth, Western Australia.
Tips for Access users -
http://allenbrowne.com/tips.html
Reply to group, rather than allenbrowne at mvps dot org.
message
Sorry Allen, still one problem. When I copied and
pasted
your code, I got an error on the Do.cmd line. I fixed
it
by eliminating a space. We have success clicking on the
form button and seeing the active document in print
preview view. However, when we send the document to the
printer, we get the following message:
"The command or action "OpenReport" isn't available
now."
*You may be in a read only...
*The type of object the action applies to isn't
currently
selected or isn't active for view
Use only the commands or macro actions that are
currently
available for this database.
Note:
There is no one else using the system so we are not in
read only mode. I do have a Macro for Opening the
report
in Print Preview mode. In the control properties of the
button, I have selected "Expression". If I delete the
Macro, the Work Order button function does not work at
all.
K
-----Original Message-----
What is the name of the primary key field of the table
the form gets its
records from? Use that name in place of "YourIdField".
--
Allen Browne - Microsoft MVP. Perth, Western
Australia.
Tips for Access users -
http://allenbrowne.com/tips.html
Reply to group, rather than allenbrowne at mvps dot
org.
Thanks again, tried your suggestion and now get the
following error:
Microsoft Access can't find the field '│' referred
to
in
your expression.
-----Original Message-----
Option Compare Database
Option Explicit
Private Sub Print_Preview_Work_Order_Click()
On Error GoTo Err_Print_Preview_Work_Order_Click
Dim stDocName As String
Dim strWhere As String
If Me.Dirty Then 'save any edits
Me.Dirty = False
End If
If Me.NewRecord Then
MsgBox "Select a record to view."
Else
stDocName = "Work Order Printout"
strWhere = "[YourIdField] = " & Me.
[YourIdField]
DoCmd.OpenReport stDocName, acViewPreview, ,
strWhere
End If
Exit_Print_Preview_Work_Order_Click:
Exit Sub
Err_Print_Preview_Work_Order_Click:
MsgBox Err.Description
Resume Exit_Print_Preview_Work_Order_Click
End Sub
Note that if YourIdField is of type Text, you will
need
extra quotes:
strWhere = "[YourIdField] = """ & Me.
[YourIdField]
& """"
--
Allen Browne - Microsoft MVP. Perth, Western
Australia.
Tips for Access users -
http://allenbrowne.com/tips.html
Reply to group, rather than allenbrowne at mvps dot
org.
Thank very much for the quick reply. I am
assuming
this
code is to be applied as an Expression in the On
Click
Control within the properties of the button. My
current
expression is as follows:
Option Compare Database
Private Sub Print_Preview_Work_Order_Click()
On Error GoTo Err_Print_Preview_Work_Order_Click
Dim stDocName As String
stDocName = "Work Order Printout"
DoCmd.OpenReport stDocName, acPreview
Exit_Print_Preview_Work_Order_Click:
Exit Sub
Err_Print_Preview_Work_Order_Click:
MsgBox Err.Description
Resume Exit_Print_Preview_Work_Order_Click
End Sub
Can you reformat this code for me as per your
example
as I
tried but it didn't work.
Thanks, much appreciated as I have basically self
taught
myself the rest and I am finding this part
frustrating
and
time consuming.
Cheers!
-----Original Message-----
This example assumes you have a numeric primary
key
named "OrderID" on your
form, and you want to open a report
named "MyReport":
Private Sub cmdPrint_Click()
Dim strWhere As String
If Me.Dirty Then 'save any edits
Me.Dirty = False
End If
If Me.NewRecord Then
MsgBox "Select a record to view."
Else
strWhere = "[OrderID] = " & Me. [OrderID]
DoCmd.OpenReport "MyReport",
acViewPreview, ,
strWhere
End If
End Sub
--
Allen Browne - Microsoft MVP. Perth, Western
Australia.
Tips for Access users -
http://allenbrowne.com/tips.html
Reply to group, rather than allenbrowne at mvps
dot
org.
My form (a work order)contains a button that
allows
the
user to print the work order in a report
format.
However,
when the user clicks and goes to print preview
mode,
the
report brings up every record in page sequence.
User
has
to search through each record to find the
correct
Work
Order number and can then print by selecting to
print
only
that page. Does anyone know how to format the
form/print
button/report/database so that clicking on the
button
only
send the active record to print preview?
Thanks!
.
.
.
.