Michelle Michy
Member
- Local time
- Today, 11:19
- Joined
- May 11, 2023
- Messages
- 46
Thanks. I found the following code and a function but i get an error
"GetUsername"
"GetUsername"
Code:
Function FileExist(FileFullPath As String) As Boolean
Dim Value As Boolean
Value = False
If Dir(FileFullPath) <> "" Then
Value = True
End If
FileExist = Value
End Function
Private Sub cmd_exportPDF_Click()
Dim fileName As String, fldrPath As String, filePath As String, LValue As String
Dim answer As Integer
Dim rst As Recordset
fileName = "ALL BOYS(MALES)-" 'filename for PDF file*
fldrPath = "C:\Users\" & GetUserName() & "\Desktop\SCHOOL REPORTS\ALL PUPILS" 'folder path where pdf file will be saved *
LValue = Now
filePath = fldrPath & "\" & fileName & Format(Date, "dd mmmm yyyy") & ".pdf"
'check if file already exists
If FileExist(filePath) Then
answer = MsgBox(Prompt:="PDF file already exists: " & vbNewLine & filePath & vbNewLine & vbNewLine & _
"Would you like to replace existing file?", Buttons:=vbYesNo, Title:="Existing PDF File")
If answer = vbNo Then Exit Sub
End If
On Error GoTo invalidFolderPath
DoCmd.OutputTo objecttype:=acOutputReport, objectName:=Me.Name, outputformat:=acFormatPDF, outputFile:=filePath
MsgBox Prompt:="PDF File exported to: " & vbNewLine & filePath, Buttons:=vbInformation, Title:="Report Exported as PDF"
Exit Sub
invalidFolderPath:
MsgBox Prompt:="ERROR!!!!!", Buttons:=vbCritical
End Sub