Hi,
I have the below code that is used to generate a report, save it as a PDF to a specific users desktop, and to print it out. Now more than one person is responsible for this activity. The problem I am running into is that the OutputTo code is specific to only the original users desktop. I want to allow any user to perform this duty from their own computer. I have potentially found a solution by utilizing Environmental functions. However, I have no experience with them and am not exactly sure how to properly integrate it into my current code.
Code:
Private Sub cmdPrint_Click()
Dim dbs As Object
Dim rst As Object
Dim strSql As String
Dim strWhere As String
strSql = "Account36MonthList" 'Select the Query where you want your information to be drawn from
Set dbs = CurrentDb
Set rst = dbs.OpenRecordset(strSql)
rst.MoveFirst
While Not rst.EOF
strWhere = " [PTSAccountNumber] = """ & rst![PTSAccountNumber] & """"
' DoCmd.OpenReport "36MonthCoverLetter", acViewNormal, , strWhere, , "False" 'Opens the report based on the strWhere and prints the report
DoCmd.OpenReport "36MonthCoverLetter", acViewPreview, , strWhere, , "False" 'Opens the report based on the strWhere to be output to PDF
DoCmd.OutputTo acOutputReport, "36MonthCoverLetter", acFormatPDF, "C:\Users\REDACTED\Desktop\Cover Letter " & rst!ClientName & " " & Right(rst![Account Number], 4) & ".pdf" 'Saves the individual report at a PDF
DoCmd.PrintOut
DoCmd.Close acReport, "36MonthCoverLetter"
rst.MoveNext
Wend
Set rst = Nothing
Me.cmdPrint.Enabled = False 'makes the button unclickable so a task does not get duplicated
End Sub
Here is a link to another forum where I found the potential solution.http://https://www.access-programmer...esktop.279464/