Open Report in Print Preview Access 2013 - ms-access

I am trying to open a report in print preview, from a form, but I am not sure where to put the function.
here is my code so far, could someone please point out what I need to add and where
DoCmd.OpenReport "Rpt_Tanc", acViewReport, WhereCondition:="[TMProfiling_ID]=" & Me!TMProfiling_ID

This is a vba Code:
You can create a command button and then write in the form on VBA like this:
Private Sub Command44_Click()
DoCmd.OpenReport "Rpt_Tanc", acViewReport, WhereCondition:="[TMProfiling_ID]=" & Me!TMProfiling_ID
End Sub
You can access the Visual Basic menu by pressing ALT + F11
Then you can select your form, In my example it is named "Form_Menu"
Please say if you need further explanations

Related

ACCESS acViewPreview not working as intended

I am trying to print preview my report (using a button on my form, see code below). When I go to do it initially, it pops up as a super small image, and I cannot right click it (so I cannot print or export it).
However, after simply entering Design View (but not changing anything), then opening the form to print the report again, it works as intended (i.e. pops up at a normal size and I can now right click the report).
Private Sub Report_Click()
DoCmd.OpenReport "Query1", acViewPreview, , Me.Query1SF.Form.Filter
End Sub
Any idea why this may be happening? What could be happening that simply going into Design View, then back to Form View, is changing how the report opens?

Access one form open at a time

What can i do for this?
I want make MS access open only one form at a time. This means i have landing form as main form and when i open another form from button in main form, the main form should close and keep only the form i open. Likewise, when i close this form with close button, it should return back to home form.How can this be done? I have tried using Macro, but macro only allows to open main form but does not close main form when i open another form. Any help would be much appreciated.
You can open the form in dialog mode, which will allow the user to only work in that form until it is closed. Any other forms will remain on the screen behind it though, but the user can not bring them into focus until the dialog form is closed.
So on your main form, you have a button to open the form. In the property sheet, click the event tab. Select the ... and choose "Code Builder". Then edit the on click procedure to look something like:
Private Sub btnOpenMyForm_Click()
On Error GoTo Err_btnOpenMyForm_Click
Dim stDocName As String
Dim stLinkCriteria As String
stDocName = "frmMyForm"
DoCmd.OpenForm stDocName, acNormal, , , , acDialog
Exit_btnOpenMyForm_Click:
Exit Sub
Err_btnOpenMyForm_Click:
MsgBox Err.Description
Resume Exit_btnOpenMyForm_Click
End Sub
if you use the button wizard, it will create code very similar to this... you just need to add the acDialog constant to the parameter of the OpenForm method.

Access VBA open form on current record

I have a form in loading records in continuous mode that looks like a datasheet. I want to have a button at the beginning of each row of data that I can click on the will open up a form for users to edit.
So far I got the edit form to load by using
DoCmd.OpenForm
This loads the first record no matter which record's button I click on. I tried the
DoCmd.Gotorecord
and this does not work. How can I fix this>?
DoCmd.OpenForm "YourFormName", acNormal, , "YourUniqueID=" & Me!YourUniqueID

An Access Form:How to get PDF of a access form

I have a Icon of PDF in my form that i have created in Access 2010. There are 3 tabs in that form; each tab have a separate form page and PDF icon is common for all the tabs.
Now I want that whenever a user click on that icon a PDF file of that form get created.
I have written this code:
Private Sub cmdPrintReportPDF_Click()
If Form_Graphs.tab_graph.Value = 2 Then
DoCmd.OpenReport "Graph_report2", acViewNormal
DoCmd.OutputTo acOutputReport, "Graph_report2"
DoCmd.Close acReport, "Graph_report2"
Else
DoCmd.OpenReport "Graph_report", acViewNormal
DoCmd.OutputTo acOutputReport, "Graph_report"
DoCmd.Close acReport, "Graph_report"
End If
End Sub
Now I wanted that whenever a user click PDF icon of the form it display the report in the PDF form.I don't want to save the report into PDF file ,just want that user can see it in PDF mode.
How can I do that?
Try the Open method of Application.Documents, e.g. Application.Documents.Open "C:\mydoc.pdf".

MS Access Print Report using VBA

I have a very VBA intensive report. When I preview it everything is great but when I print it after previewing things go wacky. I have spent many hours narrowing down the possibilities and I have conclude with a certain level of confidence that it is a bug in MS Access.
Up to this point my method for printing reports was to open the report using docmd.openreport "report". I then use the docmd.printout command so that I can set the page range, collation etc.
Is there a way to print a report directly and still be able to set options like page rage, collate etc without doing a preview first?
Thanks,
Jeff
There is unfortunately no way to do it entirely neatly in code, but it can still be done since the introduction of the WindowMode parameter of the DoCmd.OpenReport method. This makes it possible to open a report in print preview mode and have it be hidden. You can then set properties of the report's Printer object (such as the output printer and orientation), and then use DoCmd.PrintOut to print a page range.
One thing to note:
You can't do this in the report's OnOpen event, because changing anything that has an effect on the layout will not give you correct results. For instance, if in the OnOpen event, you changed from Portrait to Landscape orientation, you won't have an accurate count of how many pages there are in the report, because the report hasn't been formated at the time the OnOpen event fires. For everything but pages, though, it's OK.
The way I would implement this is with a public function and a dialog form. The function would look something like this:
Public Function PrintReport(strReport As String) As Boolean
' open report in PREVIEW mode but HIDDEN
DoCmd.OpenReport strReport, acViewPreview, , , acHidden
' open the dialog form to let the user choose printing options
DoCmd.OpenForm "dlgPrinter", , , , , acDialog, strReport
With Forms!dlgPrinter
If .Tag <> "Cancel" Then
Set Reports(strReport).Printer = Application.Printers((!cmbPrinter))
Reports(strReport).Printer.Orientation = !optLayout
Application.Echo False
DoCmd.SelectObject acReport, strReport
DoCmd.PrintOut acPages, !txtPageFrom, !txtPageTo
PrintReport = True
End If
End With
DoCmd.Close acForm, "dlgPrinter"
DoCmd.Close acReport, strReport
Application.Echo True
End Function
The dialog form would look something like this:
(source: dfenton.com)
As you can see above, I open this dialog with an OpenArg parameter, which is the name of the report. In the dialog's OnLoad event, I initialize the controls on the form:
Dim varPrinter As Printer
Dim strRowsource As String
Dim strReport As String
If Len(Me.OpenArgs) > 0 Then
strReport = Me.OpenArgs
Me.Tag = strReport
For Each varPrinter In Application.Printers
strRowsource = strRowsource & "; " & varPrinter.DeviceName
Next varPrinter
Me!cmbPrinter.RowSource = Mid(strRowsource, 3)
' first check to see that the report is still open
If (1 = SysCmd(acSysCmdGetObjectState, acReport, strReport)) Then
With Reports(strReport).Printer
Me!cmbPrinter = .DeviceName
Me!optLayout = .Orientation
End With
Me!txtPageTo = Reports(strReport).Pages
End If
End If
I use the form's .Tag property for the report name, and then do everything based on that, including making changes to report properties on the fly, which is possible because the report is open in preview mode, but not visible.
For instance, I have this AfterUpdate event behind the Layout option group:
With Reports(Me.Tag)
.Printer.Orientation = Me!optLayout
Me!txtPageTo = .Pages
End With
The reason I change the page range numbers is because changing the orientation will most likely change the number of pages. Unlike in the OnOpen event, changes to a the format properties of a report open invisibly in Print Preview mode happen immediately.
I use my standard methods for dialog forms, which is to have the Cancel and Continue buttons set the form's .Visible property to False, which allows the calling code to continue. For the Cancel button, I set the form's .Tag property to "Cancel" and check the .Tag property when the code continues in the calling context (see above).
So, this isn't as great as it would be to be able to set the page range on the Printer object directly, but it gets the job done.
One thing that would need to be changed in production code is making sure there was an error handler in the PrintReport function so that if something went wrong, Application.Echo can be turned back on (otherwise, the user might be stuck with a blank screen and unable to work). The alternative would be to just let the report appear onscreen when the DoCmd.SelectObject method is invoked. But if I'm hiding the report preview from the user, I would want to go all the way.
For more information on this, you should investigate the .Printer object in the Object Browser (F2 in the VBE), and MS Knowledge Base article 290293 is helpful in explaining the interactions between the Application.Printers collection and Application.Printer object and the ones associated with a particular report. I also found a little tutorial on the Office site that clarified a few things.
long ago, i had a very difficult case. i had to do some field creations, and moving and formatting and this could only be done one way. i took a bold approach and it turned to be the only way: i opened the report hidden and in design mode, had vba do it's stuff, and when done, the report was changed to normal and visible for display and printing.
One solution is to set the printer options in the design of the report, save those changes and the print it. The downside is that this will tie the report to a specific printer unless you go into the design and change it.
DoCmd.OpenReport "ReportName", acViewDesign, Null, Null, acHidden
Dim oRpt As Report
Set oRpt = Reports(0)
oRpt.UseDefaultPrinter = False
oRpt.Printer = Application.Printers("printer name")
With oRpt.Printer
.PaperBin = acPRBNAuto
.PaperSize = acPRPSLetter
.Copies = 1
.PrintQuality = acPRPQMedium
End With
DoCmd.Close acReport, "ReportName", acSaveYes
DoCmd.OpenReport "ReportName", acViewNormal
Set oRpt = Nothing