Does anyone know if and how i can print a PDF from Access and secure it with a digital ID? I can print to PDF on buttonclick, but now i want to secure it in the same step. This means that i need to get up the Sign with digital ID box when i export to PDF form my access file, but how is that done?
I have the following working code for printing
Filnavn = mappe & Me.IDAarstallLNr & " DOC" & " - " & Replace(Now(), ":", "") & ".pdf"
Me.txtFilnavnDigitaltSignertPDF = mappe & Me.IDAarstallLNr & " Signed date " & Replace(Now(), ":", "") & ".pdf"
DoCmd.OutputTo acOutputReport, Rapportnavn, acFormatPDF, Filnavn, True, , acExportQualityScreen
If pfUserName() <> "SGR" Then Me.File_Dato_Mappe = Date
DoCmd.RunCommand acCmdSaveRecord
End Sub
Related
I'm a beginner so please stick with me. I'm trying to make a user friendly form to calculate total cases for each worker during a date range, and to launch a report based off the same criteria. The calculation is working great but when I click the report it prompts me to enter the parameters for SWNameFilter. Thank you!
Option Compare Database
Option Explicit
Private Sub CalculateResultsSW_Click()
Dim SWReport As DAO.Recordset
Dim vChosenFilters As String
If (Not IsNull(TestSWFromDateFilter)) And (Not IsNull(TestSWToDateFilter)) Then
vChosenFilters = BuildFilterString
CasesCount = DCount("[SPN]", "TestSW", vChosenFilters)
End If
End Sub
Private Sub CloseForm_Click()
DoCmd.Close
End Sub
Private Sub Form_Load()
CalculateResultsSW_Click
End Sub
Private Function BuildFilterString()
BuildFilterString = "(ArrestDate Between #" & TestSWFromDateFilter & "# And #" & TestSWToDateFilter & "#)"
If Not IsNull(SWNameFilter) Then
BuildFilterString = BuildFilterString & " And (SWName = " & "SWNameFilter" & ")"
End If
End Function
Private Sub OpenSWReport_Click()
On Error Resume Next
DoCmd.OpenReport "SWReport", acViewPreview, , BuildFilterString
DoCmd.OutputTo acOutputReport, "SWReport", acFormatPDF, "C:\Users\" & Environ("Username") & "\Desktop\PJDSW Report.pdf", True
DoCmd.Close acReport, "SWReport"
On Error GoTo 0
End Sub
The reason that you see the popup for SWNameFilter is that the query believes that it's a name parameter, and it's asking you to enter a value for that.
The reason for it is simple, this line:
BuildFilterString = BuildFilterString & " And (SWName = " & "SWNameFilter" & ")"
The problem is that you've surrounded your variable name with double-quotes, which basically treats it like text, so your query is becoming:
And (SWName = "SWNameFilter")
This is clearly incorrect, as what you actually wanted was to include the value of the variable:
BuildFilterString = BuildFilterString & " And (SWName = " & SWNameFilter & ")"
Note the removal of the double-quotes, which will then embed the value of the variable in to the SQL instead of the word "SWNameFilter".
If SWNameFilter is a string (which I assume it is) then you'll want some double-quotes to be embedded into the SQL, which you can achieve like this in Access:
BuildFilterString = BuildFilterString & " And (SWName = """ & SWNameFilter & """)"
This will output:
And (SWName = "Value of SWNameFilter")
I have this MS Access VBA code, using MS Access 2016.
Private Sub cmdPreview_Click()
On Error GoTo Err_Handler
Dim strReport As String
Dim strDateField As String
Dim strWhere As String
Dim lngView As Long
Const strcJetDate = "\#mm\/dd\/yyyy\#"
strReport = "Sales Report V2"
strDateField = "[OrderDate]"
lngView = acViewReport
If IsDate(Me.txtStartDate) Then
strWhere = "(" & strDateField & " >= " & Format(Me.txtStartDate, strcJetDate) & ")"
End If
If IsDate(Me.txtEndDate) Then
If strWhere <> vbNullString Then
strWhere = strWhere & " AND "
End If
strWhere = strWhere & "(" & strDateField & " < " & Format(Me.txtEndDate + 1, strcJetDate) & ")"
End If
If CurrentProject.AllReports(strReport).IsLoaded Then
DoCmd.Close acReport, strReport
End If
DoCmd.OpenReport strReport, lngView, , strWhere
Exit_Handler:
Exit Sub
Err_Handler:
If Err.Number <> 2501 Then
MsgBox "Error " & Err.Number & ": " & Err.Description, vbExclamation, "Cannot open Report"
End If
Resume Exit_Handler
End Sub
The is the the code is use to make date range form work. The form lets you pick a start date and an end date. You then click a button that calls the above code and the report is generated in an new tab. What I want to achieve but have not been able to figure out so far. Is how to make the report show up in a subform/subreport of the form that contains the date range controls and then from there have a button that is clicked to open the generated report in a new tab or printing or whatever if the user is happy with the selection.
This code is from a tutorial located at www.allenbrowne.com/casu-08.html
You can set the Filter property of the enclosed report:
Me!NameOfYourSubreportControl.Report.Filter = strWhere
Me!NameOfYourSubreportControl.Report.FilterOn = True
To open the report the normal way, use your existing code.
I have a access program that let's the users click a button that will generate a backlog report, and display it then output that report to a folder on this path:
S:\ALC MASTER\Month End Reports - 2015\Senior Management\2015 Backlog Report
But for some reason I keep getting a run time error even though the file is being outputted to that folder even with the error. I just want to know if there is a way to suppress that error.
Here is My code:
Dim MonthStart As Integer
Dim MonthEnd As Integer
For i = 1 To DLookup(DMax("[rsu]", "[RSU totals]", ""), "[RSU totals]", "") Step 1
If DCount("*", "[RSU totals]", "[rsu] = " & i) > 0 Then
If Date < "#8/01/" & Year(Now) & "#" Then
setDate = "7/01/" & Year(Now)
rptName = "Sales Forecast Detail - Jan-Jun"
Else
setDate = "13/01/" & Year(Now)
rptName = "Sales Forecast Detail - Jul-Dec"
End If
fileDirName = "S:\ALC MASTER\Month End Reports - " & Year(Now) & "\" & "Senior Management" & _
"\" & Year(Now) & " Backlog Report" & "\" & Format(DateAdd("m", -1, Date), "mm") & "-" & _
Format(DateAdd("m", -1, Date), "mmm") & " - " & Format(DateAdd("m", -1, setDate), "mmm") & ".pdf"
DoCmd.OpenReport rptName, acViewReport, , "[rsu] = " & i
Reports(rptName).ReportFooter.Visible = Flase
DoCmd.OutputTo acOutputReport, rptName, "PDF Format(*.pdf)", fileDirName, True
DoCmd.Close acReport, rptName
End If
Next
Seems that my problem was i was looping through reports that didn't exist. Taking out the For loop and the initial If statement worked.
I am getting a weird problem in Access 2007 SP3. When I export a report to pdf I get the "Output To" prompt which I don't want, is there anything in my code I am doing wrong?
OverViewFile = DLookup("ExportPath", "dbo_Defaults") & "PC" & Format(Now(), "ddmmyy") & Format(Now(), "hhmm") & ".pdf"
DoCmd.OutputTo acOutputReport, "Rpt_ExportBPC", acFormatPDF, OverViewFile, False
If I've missed anything please let me know.
I don't get that prompt from Access 2007 SP3 when adapting your OutputTo with the name of my report object and giving it a valid file path for OverViewFile. So I suspect your problem is due to OverViewFile; inspect the value of that string:
OverViewFile = DLookup("ExportPath", "dbo_Defaults") & "PC" & Format(Now(), "ddmmyy") & Format(Now(), "hhmm") & ".pdf"
Debug.Print OverViewFile
DoCmd.OutputTo acOutputReport, "Rpt_ExportBPC", acFormatPDF, OverViewFile, False
You can view the output from Debug.Print in the Immediate window (Ctrl+g will take you there).
Perhaps DLookup is returning Null. You would then have a valid VBA string for OverViewFile, but it would not be a valid Windows path.
There is another issue with OverViewFile which probably doesn't contribute to the problem, but I'll suggest this because it's simpler and I think you actually want hhnn instead of hhmm in the file name (n represents minute; m represents month)
OverViewFile = DLookup("ExportPath", "dbo_Defaults") & "PC" & _
Format(Now(), "ddmmyyhhnn") & ".pdf"
Thanks in advance for any help. I have the following code which when clicked creates an email, inserts the body and customer email address and attaches a copy of the invoice. I have two questions, one is it possible to change the name of the attached file, at the moment it's just invoiceF.pdf could do with it being the reference of the delivery. AND secondly, is it possible to catch the result of the send mail? I know if the email isn't sent, just closed, access puts an information box up saying "The send object action was cancelled", i want to catch the "successfully sent" confirmation and add today's date to a box [invoiceemailed]. Thanks to anyone in advance of their help :)
Private Sub emailinvoiceF_Click()
On Error GoTo Err_emailinvoiceF_Click
If MsgBox("Email the invoice?", vbYesNo) = vbYes Then
Dim strMessage
strMessage = "Dear " & First & " " & Last & "," _
& vbCrLf & vbCrLf & "Thank you for your order: (" & DeliveryID & "), please find attached invoice." _
& vbCrLf & vbCrLf & "If you require any further information please do not hesitate to contact us." _
& vbCrLf & vbCrLf & "Kind Regards," _
& vbCrLf & vbCrLf & "SMI Hardwoods" _
& vbCrLf & vbCrLf & "Tel: 01206 396725" _
& vbCrLf & vbCrLf & "www.smi-hardwoods.com" _
Dim stDocName As String
stDocName = "InvoiceF"
DoCmd.SendObject acReport, stDocName, acFormatPDF, [E-mail address], , , "SMI Hardwoods Invoice Ref:" & DeliveryID & ".pdf", strMessage
End If
Exit_emailinvoiceF_Click:
Exit Sub
Err_emailinvoiceF_Click:
MsgBox Err.Description
Resume Exit_emailinvoiceF_Click
End Sub
DoCmd.SendObject command is very limited. It does not allow you attaching files from disk. Because of this limitation you have no control over the file name and number of files to be attached using DoCmd.SendObject.
You may find this article helpful: http://msdn.microsoft.com/en-us/library/aa167323(v=office.11).aspx.
I used Outlook.Application object in the past and found it OK. It allows to have some user interaction before sending an email. Also, it goes straight into Outlook so tracking might be easier. This approach has its own cons, though.
As per your question regarding the Success message, you can add the following to your code:
....
DoCmd.SendObject acReport, stDocName, acFormatPDF, [E-mail address], , , "SMI Hardwoods Invoice Ref:" & DeliveryID & ".pdf", strMessage
'Display success message
MsgBox("Successfully sent on: " & Date())
End If
Exit_emailinvoiceF_Click:
Exit Sub
...