DoCmd.PrintOut


Hi All,

I have a button on a form that should, when pressed, save the form and print it out.

However at the moment it prints out all forms. I was wondering if anyone could tell me the code to print out the current form only?

Thanks in advance

James Aubrey


Sponsored Links:



I'm trying to print 2 copies of the report: rptSalesReportDaily.


	Code:
	DoCmd.OpenReport "rptSalesReportDaily", acViewNormal

DoCmd.PrintOut acSelection, , , , 2

With the code above the first copy is indeed the report, the second
copy is a screenprint of the form the print button is sitting on.

Any ideas how to solve this?

Thanks
Catalina




I have a form that I printout using DoCmd.Printout

It used to offer pdf but on the same PC it now it only offers xps.
The xps makes some characters huge so is useless.

What happend to the pdf option?




Printing Numerous Labels using For Next loop is not working in Access 2010
But works OK in Access 2003
Label is 1 page size 4x3
Request is to print 1..300 labels sequenced (Autonumber)

I am using the followin code when Print_selected() on a form:
DoCmd.OpenReport "rptBarcodeLabel", acViewPreview
DoCmd.SelectObject acReport, Screen.ActiveReport.Name
Nmax = Me.CmbCounterStart 'start at this number
For i = 1 To nmax
'add sequece to show 1, 2,...on the report
Me.CmbCounterStart = Me.CmbCounterStart + 1
DoCmd.PrintOut acPages, 1, 1, , 1
Next i

The procedure works ok but it will just print 5 or 6 or 7 but not more
However if I do use
DoCmd.SelectObject acReport, True
DoCmd.PrintOut acPages, 1, 1, , nmax 'but no sequeced

it print nmax copies without any problem

Please advice
Thank you




Can anyone show me how to use the code
DoCmd.PrintOut acPages, Me.TxtFrom, Me.TxtTo
to print a report from a form?




Is there anyway to print preview when the DoCmd.PrintOut action is performed?

I have a database that is using the docmd.printout method to give a screen shot of a form, and the users want to print preview this, if possible.

Thank you,

T.J.




Hi Everyone!
I'm a newbie at this ,so please be patient.

I need to print out membershipcards to a pre-perforated A4 sheet, left to right in 2 columns and 5 rows, but want to be able to set the starting position as well at times.

Scenario:
I can print out 3 Family cards and 5 singles cards, each type based on their own form, so they have to be printed separately.
I print out the Family cards and to save paper (expensive) I use the same sheet again to print the rest. The first card of the Singles cards, must now be positioned to start printing in row 2, column 2 in the perforated areas.
To do this I have to first print 3 "blanks", or position the "card" exactly on the sheet. To blank out these with a little code in the forms works fine, but all this is completely ignored by the report.

The report is printed based on a preview of the form:

DoCmd.OpenForm stDocName, acPreview
DoCmd.SelectObject acForm, stDocName, True
DoCmd.PrintOut acPrintAll, , , Q, A, S
DoCmd.Close acForm, stDocName

I'm stumped! I don't know if I should continue this line of thought and find a solution (maybe there is one already!), or do a 180. Could some kind soul out there please give me a kick in the right direction?




I am trying to print the first page of a report using the following VBA:

DoCmd.SelectObject acReport, "rptMyReport", True
DoCmd.PrintOut acPages, 1, 1, , 2

The issue I have is that the first copy always comes out as a blank page. Setting the number of copies to 1 gives me only a single blank page. If I set the number of copies to 2, I get 1 blank page and one copy of the report. If I set the number of copies to 3, I get 1 blank page and 2 copies of the report.

I have looked through everything I can identify in the report that may be causing this and I am stumped.




Hello All,

I'm having an issue with a print button at the moment. I can print a specific record via criteria, and i can print a required number of copy's from a field. But, i can't do both in one statement! I need to print a report x number of times, based on a field.

Im trying to use this at the moment:


Private Sub printdelLabels_Click()
DoCmd.OpenReport "shiplabel", acViewPreview, , "ID = " & Me.ID
DoCmd.PrintOut , , , , Me.noofpallets
End Sub


Which results in printing the correct form once from the open report, and then the DoCmd.printout is printing the form x noofpallets.

As the openreport line, as obvious has nowhere i can input the noofpallets query, how do i combine both?

Sorry for a n00b question, i have trawled previous DoCmd.PrintOut posts and not been able to answer it myself




Hi folks,

I have a little challenge on my hands at the moment and cant seem to google/search/code up the answer myself (if there is one).
I currently have a loop in VBA that does (in it's simplified form)

DoCmd.OpenQuery
DoCmd.PrintOut
DoCmd.Close

For a few hundred queries. What i now have the challenge of doing is filtering the query using VBA in the same way as you would manually (open the query, right click column, filter for, "text here", then print.)
The reason I dont want to edit the queries is firstly because there are so many and secondly, a bit of vba is far more efficient.

Does anyone know if this is possible? Please note that all the queries are oracle pass through queries, not access queries, which may/may not make things a little harder?

Thank you so much for any help. I look forward to any response.




Good Afternoon,

Does anyone know if it is possible to click a button on a form "A" and have it print the recordset that is in the subform on the same form "A"?

Here is what I have so far but the error is telling me it is not recognizing my subform...

PHP Code:
Dim db As DAO.Database
Set db = CurrentDb
Forms("DD_Snip_TBL subform").Printer.Orientation = acPRORLandscape
DoCmd.PrintOut acSelection, 1, 1, acLow, 1, False 
Thanks for any help you can provide.

Tallman.




Is is possible to print a report (that's already been generated and in "preview" mode) by hitting a "print" button that's on a form?

I'm trying to do this with
DoCmd.PrintOut

I realize that this command will print out the currentlyactive object, so I'm thinking I have to make the Report active first with some type of .SetFocus command, but once that .SetFocus has been run, the DoCmd.PrintOut code on the form wouldn't be run...




I have some code that I have used printout in for the 1st time. It prints the active report fine but then also prints the form "FRMmainboard" afterwards(which is NOT open). If I comment it out it still does it so I am confussed. A number of othe forms have been opened and closed since FRMmainform was last used, I 1st thought It may have been a " hangover" in the memory, if such a thing could occur I am not sure. Can anybody explain why this may be occuring?


This is the end of the code....

DoCmd.OpenReport "RPT CashDeclareTempPrint"
DoCmd.PrintOut acPages, 1, 1
DoCmd.SetWarnings True
DoCmd.OpenForm "FRMMainboard"




i use this code it work fine . my problem is if no data i got my form print as number of rows x2.


CODE
Private Sub cmdPrint5_Click()
On Error Resume Next
DoCmd.RunCommand acCmdSaveRecord
Dim stDocName As String
DoCmd.OpenReport "affichage", acViewPreview, WhereCondition:=" PrintYesNo = False and notification=false "
DoCmd.SetWarnings False
DoCmd.SelectObject acReport, "affichage"
DoCmd.PrintOut acPages, , , , 2
DoCmd.Close acReport, "affichage"
DoCmd.RunSQL "Update tbl1 set PrintYesNo = true where PrintYesNo = false "
DoCmd.SetWarnings True
End If
End Sub


any help please




Hi all

I am trying to open the same popup dialog box form from different forms for the same purpose(Print confirmation), and I don't want to copy the same form and use different copies for different forms.

The way I would like to get around this is to use a global variable and set the variable according to the form that opened the popup and when user clicks cancel the dialog form will close and the corresponding form in Print preview to close and the original form that opened these to reopen in normal mode


The variable in question is Previous_Form
Here is my code for a button in the control panel form:

	Code:
	Private Sub cmd_Print_Book_list_Click()
'Summery:
'This will print the form "frm_Nest_frm_Books_Descriptions_in_Store_DatasheetView_Popup"

'*********************************************************************************************************

DoCmd.OpenForm "frm_Nest_frm_Books_Descriptions_in_Store_DatasheetView_Popup", acNormal, , , acHidden 'this will open the
form "frm_Nest_frm_Books_Descriptions_in_Store_DatasheetView_Popup" in print preview
Form_frm_Nest_frm_Books_Descriptions_in_Store_DatasheetView_Popup.OnClose = ""
Form_sfrm_Books_Descriptions_in_Store_Datasheet_Popup.OnLoad = ""
DoCmd.OpenForm "frm_Nest_frm_Books_Descriptions_in_Store_DatasheetView_Popup", acPreview, , , acFormReadOnly
DoCmd.Maximize ' this will maximize "frm_Nest_frm_Books_Descriptions_in_Store_DatasheetView_Popup"
DoCmd.OpenForm "dlg_print_conferm", acNormal, , , acFormReadOnly 'this will open the print conferm dialog box
Previous_Form = """frm_Control_Panel"""
DoCmd.Close acForm, "frm_Control_Panel", acSaveNo 'this will close form "frm_Control_Panel"
End Sub

Here is the code in dialog box:

	Code:
	Sub cmdCancel_Click()

DoCmd.Close acForm, "dlg_print_conferm", acSaveNo
DoCmd.Close acForm, "Form_frm_Nest_frm_Books_Descriptions_in_Store_DatasheetView_Popup", acSaveNo
DoCmd.OpenForm Previous_Form, acNormal, , , acFormEdit, acNormal
DoCmd.Maximize

End Sub
'__________________________________________
Private Sub cmdOK_Click()
On Error GoTo NoPrinter
DoCmd.Close acForm, "dlg_print_conferm", acSaveNo
    
With Form_frm_Nest_frm_Books_Descriptions_in_Store_DatasheetView_Popup
    DoCmd.PrintOut acPrintAll, , , acDraft, 1, True
End With

DoCmd.Close acForm, "Form_frm_Nest_frm_Books_Descriptions_in_Store_DatasheetView_Popup", acSaveNo

DoCmd.OpenForm Previous_Form, acNormal, , , acFormReadOnly, acNormal
DoCmd.Maximize
Exit Sub
NoPrinter:
MsgBox "You do not have your printer ready"
DoCmd.Close acForm, "Form_frm_Nest_frm_Books_Descriptions_in_Store_DatasheetView_Popup", acSaveNo
DoCmd.OpenForm Previous_Form, acNormal, , , acFormReadOnly, acNormal
DoCmd.Maximize
End Sub

Does any one have any ideas?

Thanks in advance




This is for a packing labelling printer at work. And basically it prints out the destination of where package is to be sent by courier. Problem is if there are more than 1 package i.e. 10 packages it will print out 10 labels of that address and on the label. There is a "...... of ......" printed on the label where we're supposed to write "1 of 10", "2 of 10" etc.. with a pen marker on each label so the courier knows how many packages go together. I'd like to know if there is a way to get MS Access to do it for us, as in print on these dotted lines "1 of 10" "2 of 10" etc... rather than us having to write it with pen marker which can take a while when you have 10+ labels to write on...

The programmer that designed the system for us has left the company and we've no one experienced enough in VB to do it for us. I havent any knowledge in MSA but have done other scripting languages in my IT courses and I've looked around in this access printing program to understand a little bit of what's going on when it prints the label..

There is only 1 macro file and it contained this sub in it which I think may be where I'd need to make some changes or add a few lines of code to get it to number each label..

Public Sub PrintTheLabels2()
Dim CustomerCode As String, numCopies As String, strAddress As String

DoCmd.Close acReport, "LabelPrint"
CustomerCode = InputBox("Enter a Customer Code", "Print Labels, Customer Code")
numCopies = InputBox("Enter the number of copies to print", "Print Labels, Copies")
If CustomerCode = "" Or numCopies = "" Then
Exit Sub
End If

' DoCmd.OpenReport "LabelPrint2", acViewPreview, , "[Customer Code] = '" & CustomerCode & "'"

DoCmd.OpenReport "LabelPrint", acViewPreview, , "Trim([Customer Code]) = '" & CustomerCode & "'"

DoCmd.PrintOut acPrintAll, , , , numCopies
DoCmd.Close


End Sub




Firstly how do I go about editting the report so I can create a textbox where it will place the numbers over the "...... of ......"?

Then how do I get this macro to print the number of copies onto this textbox incrementing the "....." of "10" by 1 in every print of the label?

This is probably not the correct approach just going by instincts on what I see and how I think it will work. If you have a better suggestion or solution to the problem please tell me how..

Thank You!




I am using Access 97 to print out the form.
I would like to have one command button whereby it can specify a canon printer to print the form and another command to use Microsoft office document image writer to save the same form as an image.


	Code:
	Private Sub Print_Click()
‘using canon printer to print the form
Docmd.PrintOut

End Sub

Private Sub Save_Click()
‘using Microsoft office document image writer to save the form as a .mdi file
Docmd.PrintOut’

End Sub


Is there a way to specify which printer to print the form?
thanks.




Hello,
Perhaps someone can help me with this one. I am trying to have a 'current' form print automaticly when the form has been filled out completly. The last event that properly happens on the form is that a Pop-up form appears and prompts the user to take action from there. The print code needs to run before the pop up form appears, but however I try to get it to print, I get: "Run-time error 2585 - This action can't be carried out while processing a form or report event"

The code I've been using is:
DoCmd.PrintOut acSelection, , , acHigh

I have tried it at lost focus, got focus, and after update of different controls on the form. FYI, the Pop-up form opens upon got focus of the last control, and both of the last 2 controls on the 1st form are locked.

thanks,
chuck




I am trying to place code into my on click event of my print report button that will print a report to letterhead and plain paper. Ther are two drawers on the printer one is for letter and the other is for letterhead. Listed below is my code for accomplishing this task. One problem I have is that Access is looking for an end sub right away. It's almost like it does not recognize the function. Any help would be greatly appreciated.



Private Sub Print_Invoice_OnClick()


Function twotrayprinting(WAMInvoice) As Integer
'
'Note: The report gets run twice, once for each tray.
'
'Returns: TRUE = Success; FALSE=Error
'
Const MAX_PAGES = 999

'Open the report in DESIGN view
On Error GoTo TTP_Error
DoCmd.Echo False
DoCmd.OpenReport WAMInvoice, A_DESIGN

'Switch to upper tray and print first copy
SetReportTray Reports(WAMInvoice), R_UPPR_Tray
DoCmd.PrintOut A_PAGES, MAX_PAGES


'Switch to lower tray and print second copy
SetReportTray Reports(WAMInvoice), R_Lower_tray
DoCmd.PrintOut A_PAGES, MAX_PAGES

'Close the report
DoCmd.SetWarnings False
DoCmd.Close A_REPORT, WAMInvoice
DoCmd.SetWarnings True
DoCmd.Echo True
'Twotrayprinting = true

TTP_exit:
Exit Function

TTP_Error:
'Twotrayprinting=false
DoCmd.Echo False 'restore screen echo
Resume TTP_exit



End Function
End Sub




I am printing 2 copies of the first page to letterhead and the rest of the report prints to plain paper. The report prints fine if there are multiple pages to the report, however if there is only one page, the report prints two copies to letterhead and one copy to plain paper. The copy that goes to plain paper only shows the page heading and the page number says page 2 of 1. Listed below is a sample of my coding. Any help with this would be greatly appreciated.

Type zwtDevModeStr
RGB As String * 94
End Type
Type zwtDeviceMode
dmDeviceName As String * 16
dmSpecVersion As Integer
dmDriverVersion As Integer
dmSize As Integer
dmDriverExtra As Integer
dmFields As Long
dmOrientation As Integer
dmPaperSize As Integer
dmPaperlength As Integer
dmPaperWidth As Integer
dmScale As Integer
dmCopies As Integer
dmDefaultSource As Integer
dmPrintQuality As Integer
dmColor As Integer
dmDuplex As Integer
dmResolution As Integer
dmTTOption As Integer
dmCollate As Integer
dmFormName As String * 16
dmPad As Long
dmBits As Long
dmPW As Long
dmDFI As Long
dmDRr As Long
End Type


Sub setPaperSource4(rptName As String)
Dim rpt As Report
Dim DM As zwtDeviceMode
Dim DevString As zwtDevModeStr
Dim DevModeExtra As String

DoCmd.SetWarnings False
' Set Paper Tray for page 1
DoCmd.OpenReport "Reprint cert report official", acViewDesign, , "Invoice_no = " & INVOICE_NO
Set rpt = Reports("[Reprint cert report official]")
DevModeExtra = rpt.PrtDevMode
DevString.RGB = DevModeExtra
LSet DM = DevString
DM.dmDefaultSource = 2 '1 = Upper Tray, 2 = Lower Tray, 5 = _Envelope Feeder
LSet DevString = DM
Mid$(DevModeExtra, 1, 68) = DevString.RGB
rpt.PrtDevMode = DevModeExtra
DoCmd.Save acReport, "Reprint cert report official"
DoCmd.SelectObject acReport, "Reprint cert report official", True
DoCmd.PrintOut acPages, 1, 1, copies, 2

' Set Paper Tray for page 2
DoCmd.OpenReport "Reprint cert report official", acViewDesign
Set rpt = Reports("[Reprint cert report official]")
DevModeExtra = rpt.PrtDevMode
DevString.RGB = DevModeExtra
LSet DM = DevString
DM.dmDefaultSource = 1 '1 = Upper Tray, 2 = Lower Tray, 5 = _Envelope Feeder
LSet DevString = DM
Mid$(DevModeExtra, 1, 68) = DevString.RGB
rpt.PrtDevMode = DevModeExtra
DoCmd.Save acReport, "Reprint cert report official"
DoCmd.SelectObject acReport, "Reprint cert report official", True
DoCmd.PrintOut acPages, 2, 20, copies, 2

End If
End Sub




The existing code on Access97 uses these commands to print out a certain number of pages on a report that's opened in preview mode:

DoCmd.OpenReport theReport, acPreview
DoCmd.PrintOut acPages, intStartPageToPrint, intEndPageToPrint

I have been asked to incorporate another report which is printed at the same time as the report above (to print labels to another printer).

The problem I have is that if I open the first report in acPreview mode, then open the second report in acPreview mode (ie one report is displayed on top of the other), then I need to print both reports without closing any of the reports. Is this possible?

At the moment I use:
DoCmd.OpenReport theReport, acPreview
DoCmd.OpenReport the2ndReport, acPreview
DoCmd.PrintOut acPages, intStartPageToPrint, intEndPageToPrint
but it only print the2ndReport info.