printing from a form button

  • Thread starter Thread starter kathyaccess
  • Start date Start date
K

kathyaccess

I designed a form with a button that when clicked, allows
the user to see a print preview using a report. However,
when the print preview opens, it does not select the
record the user is working on. User has to arrow through
all records in the table to find the specific report to be
printed. Does anyone know how to configure the click on a
button, print preview report to only select the record the
user is working on?
 
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
 
does this code need to be in the form properties or the button properties ? Also I am getting Black in some of my fields on my report when printed. The fields which are printing black are only those which row source type are "field list".... Any help would be GREATLY appreciated.

also any know of relief for ACCESS HEADACHES?
 
Set the On Click property of the button to:
[Event Procedure]
Click the Build button (...) beside this. Access opens the code window, and
does the first and last line for you. Paste the rest in between.

The selected item prints in reverse video. The best idea is to create a
report with text boxes (not combos or list boxes) and you can lay it out for
print (often different than the form layout).

--
Allen Browne - Microsoft MVP. Perth, Western Australia.

Reply to group, rather than allenbrowne at mvps dot org.

BDP said:
does this code need to be in the form properties or the button properties
? Also I am getting Black in some of my fields on my report when printed.
The fields which are printing black are only those which row source type are
"field list".... Any help would be GREATLY appreciated.
 
Thanks Allen, that is working somewhat It opens the print preview window of the report and I am able to print from there, is this correct or have I done something else wrong?

Also I am experiencing a black field in the report and the form. This fields row source is Field list coming from a table. Any help you may be able to offer would be great

Barr
 
If you want to print directly without previewing, change:
acViewPreview
to
acViewNormal

I answered somebody's question about the "black" field: you must be using a
listbox (or possibly combo box)? The selected record will be reverse video.
While it is possible to set the list box to reverse that (i.e. tell it to
use white text on a black background so it prints in reverse of the
reverse), the better solution is to use a query as the source for the
report, and include the lookup table there, so you can use a text box
instead of a listbox on your report.

Note that you may need to use an outer join in the query to get all the
records. If you are not sure what that means, see:
http://allenbrowne.com/casu-02.html

--
Allen Browne - Microsoft MVP. Perth, Western Australia.

Reply to group, rather than allenbrowne at mvps dot org.

BDP said:
Thanks Allen, that is working somewhat It opens the print preview window
of the report and I am able to print from there, is this correct or have I
done something else wrong?
Also I am experiencing a black field in the report and the form. This
fields row source is Field list coming from a table. Any help you may be
able to offer would be great.
 
Thanks for the help Allen, that solved my current issue's. I have saved your site to my favorites and will probably be a regular visitor as I attempt to learn more about access.
 
Back
Top