I am trying to print an access report with PDF creator but a strange problem is happening:
If I print the report with PDF creator I get a white square in the report (see the blow instruction):
DoCmd.OutputTo acOutputReport, "E_Dossier", acFormatPDF, first & strReportName, False, , 0 ,
but if I open it with this instruction instead, the report is correct and I don't have white squares.
DoCmd.OpenReport "E_Dossier" ' , acViewPreview
Any ideas please?
I have had issues like that in the past. What I do is I open the report in hidden preview, then export to PDF and then close the preview. That seems to deal with most of the weird differences between print and export.
Edit: This is a function I use to generate PDFs
Public Sub PrintReportPDF(ReportName As String, Filename As String, Optional ReportArgs As String = "", Optional WhereCondition As String = "")
DoCmd.OpenReport ReportName, acViewPreview, , WhereCondition, , ReportArgs
DoCmd.OutputTo acOutputReport, "", acFormatPDF, Filename, False
DoCmd.Close acReport, ReportName
End Sub
Another thing to check is that you have a regular default printer (one that would print the report properly if the report was printed to it).
i have joined an example of generated white square #Marcucciboy2
Related
I am new to access and trying to practice some fundamentals. I am trying to generate a report based on user input from a form.
When the user selects an address a report should be generated with one instance of the address.
As of right now when I create the report on the click from the form.
There are multiple instances been generated of the same address.
The table i am using
AddressLine1
123 Main St.
555 Happy Ln.
456 Main St.
6598 W Street St.
code:
Option Compare Database
Private Sub generateReport_Click()
Dim text As String
text = Me.custAddress
DoCmd.OpenReport "Generation", acViewPreview, "AdressLine1=" & text
End Sub
The outcome is the following...
[![Report outcome][1]][1]
[1]: https://i.stack.imgur.com/wr1Zg.png
I only want it to be printed once.
NVM fixed it by adding a wherecondition
Option Compare Database
Private Sub generateReport_Click()
Dim text As String
text = Me.custAddress
DoCmd.OpenReport "Generation", acViewPreview, text, _
WhereCondition:="AddressLine1 = '" & text & "'"
End Sub
I have a main menu where users type in a name of a station (text box) and the name of a cohort (text box) and it would open a new form based on these values. For example, if "New York" was entered for a station and "1b" was entered for cohort, then the form would filter to only show data that have both. However, I am getting a data mismatch error.
The fields text boxed at my main menu are called "detailed_s_station" and "detailed_s_cohort". The names of the respective fields in the form I want to filter these values are called "station" and "cohort".
I can get this to work if there are only one set of criteria (e.g., if I just search for the cohort or just search for the station), however something is going on with my AND here. Any help is appreciated to help me get rid of this data mismatch error.
Private Sub Command41_Click()
Dim stDocName22 As String
Dim stLinkCriteria22 As String
stDocName22 = "frm_scans"
stLinkCriteria22 = "[station] ='" & Me![detailed_s_station] & "'" And "[cohort] ='" & Me![detailed_s_cohort] & "'"
DoCmd.OpenForm stDocName22, , , stLinkCriteria22, acFormEdit, acWindowNormal
End Sub
The problem that you are having is how you are joining the string together. Instead try:
Private Sub Command41_Click()
Dim stDocName22 As String
Dim stLinkCriteria22 As String
stDocName22 = "frm_scans"
stLinkCriteria22 = "[station] ='" & Me![detailed_s_station] & "' And [cohort] ='" & Me![detailed_s_cohort] & "'"
DoCmd.OpenForm stDocName22, , , stLinkCriteria22, acFormEdit, acWindowNormal
End Sub
If you ever have problems like this in future, a quick Debug.Print strLinkCriteria22 would show you the contents of the string that is causing problems.
Regards,
The situation
I have a report which is used for a receipt,
I made 2 buttons to extract it - one is to get a PDF and the other is to print. If using PDF then i need the background image. If printing then i don't (because it is being printed on pre-printed paper).
This is the code for PDF:
DoCmd.OpenReport "Receipt", acViewPreview, , "OrderID = " & Me.OrderID, acHidden, "PDF"
DoCmd.OutputTo acOutputReport, "Receipt", acFormatPDF
DoCmd.Close acReport, "Receipt", acSaveN
This is the code for print:
DoCmd.OpenReport "Receipt", acViewNormal, , "OrderID = " & Me.OrderID, acHidden, "Prt"
I put the openargs so that i can set the OnLoad to hide the background when printing.
The issue
It seems that there is no OnLoad when opening the form with acViewNormal (used to auto print it)
So
Is there another way to program this or is there a way to make the background appear in print preview (for PDF) but not in actual print?
Any assistance will be appreciated.
The On Format event of the appropriate report section runs for both Print and Print Preview.
So this event is the best place to put this functionality into.
I have an access form that runs a query. There is a command button on the form that I want to send an email with the query results attached in an excel spreadsheet. Using the code below I am able to attach the results and send the email ok. I would like to be able to format the email body so that it is more noticeable. I'm not really sure how to go about doing this and still have my query attached. I have also created an email template that I would use but I haven't been able to figure out how to use the template and attach the query results. I'm open for any suggestions. Any help would be greatly appreciated.
DoCmd.SendObject acQuery, "BoxOrder", "ExcelWorkbook(*.xlsx)", "me#home.com", _
"John#hishome.com", "", "BOX ORDER", _
"ALL BOXES STITCHED" & vbCrLf & "Questions: Please Call Me" & _
vbCrLf & "555-555-5555 x 66654", True, True
You could follow the Article from MS.
A proportion of the code is as follows:
Set ola1 = New Outlook.Application
Set mai1 = ola1.CreateItem(olMailItem)
mai1.To = strTo
mai1.Subject = strSubj
If bolHTML = True Then
mai1.HTMLBody = strBody
Else
mai1.Body = strBody
End If
mai1.Display
If you use the HTML (set bolHTML = True) version you can either have an RTF control on a Form and pass the formatted text over or hardcode your HTML with the formatting you need. Just set the "strBody" to the message you want.
Then you need to look into the Attachments.Add (MS Article) if you want to use the above code with your original purpose.
There's a full 599CD Email Seminar you could follow if you're going to be doing a lot with Email in Access.
i Have used this code in access 2010 for genrating pdf file
DoCmd.OutputTo acOutputReport, "Graph_report2", ".pdf", "C:\Graph_report2.pdf", True
it is working fine in access 2010 but when i open my access database in access 2007 it gives Runtime error 2501 that 'The OutputTo action was cancelled' and not pdf file is open.
Big problem !what i do? Plz Help
DoCmd.OutputTo acOutputReport, "Graph_report2", ".pdf", "C:\Graph_report2.pdf", True
should be:
DoCmd.OutputTo acOutputReport, "Graph_report2", acFormatPDF, "C:\Graph_report2.pdf", True
Rob
Can I add that apart that one needs to install an add in for PDF output and then start Access 2007, http://www.microsoft.com/en-us/download/details.aspx?id=9943
If one tries to save the file in a directory that does not exist, this error will also pop up.
Here is a function for PDF output:
Function PrintToPDF(SrcReport As String, DestPath As String, DestFile As String, ShowPdf As Boolean)
On Error GoTo PrintToPDF_Err
'ScrReport = The report Name to output as PDF
'DestPath = Destination path for PDF file e.g. C:/DatabaseReports/Financial/
'DestFile = File name for the PDF file being created, but without the file extension, one can add date to it
'Showpdf = launch pdf viwer and display this PDF output
DoCmd.OutputTo acOutputReport, SrcReport, "PDFFormat(*.pdf)", DestPath & DestFile & ".pdf", ShowPdf, "", 0, acExportQualityPrint
PrintToPDF_Exit:
Exit Function
PrintToPDF_Err:
MsgBox Error$
Resume PrintToPDF_Exit
End Function