Originally Posted by
Gicu
You don't need to have one button just to open the report; in the click event of your current button on the form you just add a few more lines before the Docmd.OutputTo. If you filter the report to only include the current record you wouldn't even needs those extra lines, just modify the existing one to output the report instead of the form.
Cheers,
Ok @Gicu. Would you be able to check my work? I just want to make sure I am doing it correctly. It seems to be working. Here is the code:
Code:
Private Sub cmdProcessToPDF_Click()Dim FileName As String
Dim FilePath As String
If Me.NewRecord And Me.Dirty Then
MsgBox "Please Save Record Before Exporting.", vbInformation, "Requirement"
Me.txtTabStopper2.SetFocus
Exit Sub
End If
If Me.NewRecord And Me.Dirty = False Then
MsgBox "Please Create And Save Record Before Exporting.", vbInformation, "Requirement"
Me.txtTabStopper2.SetFocus
Exit Sub
End If
If Me.txtProcessed.Value <> 0 Then ' to let user know that they already processed a PDF for this record
If MsgBox("Already Processed." & vbCrLf & vbCrLf & _
"Are You Sure You Want To Process To PDF Again?", vbYesNo, "Export") = vbYes Then
FileName = "Example " & Format(Me.txtDateSent, "yyyymmdd") & "_Ref-" & Me.txtRefNum
FilePath = "K:\READY\" & FileName & ".pdf"
'FilePath = CreateObject("WScript.Shell").SpecialFolders("Desktop") & "\" & FileName & ".pdf"
DoCmd.OpenReport "Request_Screenshot_report", acViewReport, , "[Ref Num] =" & _
Me.txtRefNum
DoCmd.OutputTo acOutputReport, "Request_Screenshot_report", acFormatPDF, FilePath
Me.txtProcessed.Value = Me.txtProcessed.Value + 1 ' showing the amount of times it was processed
Me.Dirty = False
MsgBox "PDF File Was Exported As (Example yyyymmdd_Ref#.pdf) To Network Folder.", _
vbInformation, "Notification"
DoCmd.Close acReport, "Request_Screenshot_report"
Me.txtRefNum.SetFocus
Exit Sub
Else
Me.txtRefNum.SetFocus
Exit Sub
End If
End If
If MsgBox("Process To PDF?", vbYesNo, "Export") = vbYes Then
FileName = "Example " & Format(Me.txtDateSent, "yyyymmdd") & "_Ref-" & Me.txtRefNum
FilePath = "K:\READY\" & FileName & ".pdf"
'FilePath = CreateObject("WScript.Shell").SpecialFolders("Desktop") & "\" & FileName & ".pdf"
DoCmd.OpenReport "Request_Screenshot_report", acViewReport, , "[Ref Num] =" & _
Me.txtRefNum
DoCmd.OutputTo acOutputReport, "Request_Screenshot_report", acFormatPDF, FilePath
Me.txtProcessed.Value = Me.txtProcessed.Value + 1
Me.Dirty = False
MsgBox "PDF File Was Exported As (Example yyyymmdd_Ref#.pdf) To Network Folder.", _
vbInformation, "Notification"
DoCmd.Close acReport, "Request_Screenshot_report"
Me.txtRefNum.SetFocus
Else
Me.txtRefNum.SetFocus
End If
End Sub
So basically the user clicks the process button and prompt user to ask if they want to process to PDF and if they click yes it will flash a blank window which I think is the report and then a msgbox will appear saying it is finished. The problem I am facing right now is that I have a label and a text box, separate from each other that shows up on the PDF even though I have the display property for those controls set at "Screen Only". Everything else like the buttons and what not are not showing up so I can't figure out why this one label and text box is showing up. Lastly, the reference number is showing in green font. I want the reference number to show on the PDF but in black font. I tried changing the font color but I think it may be VBA or conditional formatting that is causing it to show as green. When the user is creating a new record, the reference number shows as green but once they save the record, it will change the font to black. When I process to PDF, the report reference number is in black font so not sure why it turns it back to green.
UPDATE: I figured out how to get rid of the label and text box. I just removed everything on the report that I did not want showing up in the PDF. I also had to remove all the VBA in the report since it was not needed and causing compile errors when debugging. The report really does copy every single thing from the form when saving object as report. lol