Access Form Convert to PDF VBA Code not working (1 Viewer)

Mackbear

Registered User.
Local time
Today, 11:07
Joined
Apr 2, 2019
Messages
168
Hi Mackbear,

You should still be able to save it to a desktop folder.

I wouldn’t have thought that a different case letter would stop it from being able to save to that folder.
So definitely try Gasman’s recommendation to debug.print or msgbox the fldrPath variable might help you identify the issue with the path.

You could also try changing the particular letter to uppercase.
If it’s the first letter try:

Code:
strusername = StrConv(strusername,3)

Before building your path variable.

Just a thought.


Sent from my iPhone using Tapatalk[/QUOTE

Not sure why though, that is what I see as well when I debug print, I see the flder path, and that's how I figured out the lower case upper case difference, environ user name function uses upper case and the folder name is lower case...anyway i tried saving it somewhere else and it works, but the users complain that it takes about 2 to 3 minutes to complete for some reason so I just created it as an attachment... thank you very much!
 

SuhailSarwar

New member
Local time
Today, 21:07
Joined
Mar 31, 2023
Messages
1
Hello everyone, hope you are all doing fine. I hope I can get some help on this code I found by googling. This always says I have Invalid folder path. I don't know which I causing the error. Here's the code:

Dim fileName As String, fldrPath As String, filePath As String, strusername As String

Dim answer As Integer:banghead:

strusername = Environ("UserName")
fileName = "Template-Please Rename" 'filename for PDF file*
fldrPath = "C:\documents and settings" & strusername & "\Desktop" 'folder path where pdf file will be saved *


filePath = fldrPath & "" & fileName & ".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: Invalid folder path. Please update code.", buttons:=vbCritical
fldrPath = "C:\documents and settings" & strusername & "\Desktop" 'folder path where pdf file will be saved *
filePath = fldrPath & "" & fileName & ".pdf"

CORRECT THE ABOVE LINES AS

fldrPath = "C:\documents and settings\" & strusername & "\Desktop\" 'folder path where pdf file will be saved *
filePath = fldrPath & fileName & ".pdf"

OR YOU CAN SIMPLY WRITE

filePath = "C:\documents and settings\" & strusername & "\Desktop\" & fileName & ".pdf"
omitting fldrPath
 

theDBguy

I’m here to help
Staff member
Local time
Today, 09:07
Joined
Oct 29, 2018
Messages
21,358
fldrPath = "C:\documents and settings" & strusername & "\Desktop" 'folder path where pdf file will be saved *
filePath = fldrPath & "" & fileName & ".pdf"

CORRECT THE ABOVE LINES AS

fldrPath = "C:\documents and settings\" & strusername & "\Desktop\" 'folder path where pdf file will be saved *
filePath = fldrPath & fileName & ".pdf"

OR YOU CAN SIMPLY WRITE

filePath = "C:\documents and settings\" & strusername & "\Desktop\" & fileName & ".pdf"
omitting fldrPath
Hi @SuhailSarwar

Welcome to AWF!

Just FYI, this is an over-three-year old thread. But we still appreciate your input.

Cheers!
 

Users who are viewing this thread

Top Bottom