Avatar of sheng wee
sheng wee

asked on 

Ms Access "If Dir function, Then, Else, End if"

Yesterday it was working just fine. and somehow today I re-test the folder was empty but the pdf was saved version 2.

filename = Me.Ref_Number
filepath = "T:\ACCESS DATABASE\" & filename & "\Commercial\" & filename & ".pdf"

filename2 = Me.Ref_Number & "(v2)"
filepath2 = "T:\ACCESS DATABASE\" & filename & "\Commercial\" & filename2 & ".pdf"

If Dir("T:\ACCESS DATABASE\" & filename & "\Commercial\" & filename & " .pdf", vbDirectory) <> "" Then
DoCmd.OutputTo acOutputReport, "OrderCustomerReport", acFormatPDF, filepath
MsgBox "Quotation has been saved successfully", vbInformation, "Save Confirmed"
Application.FollowHyperlink "T:\ACCESS DATABASE\" & Me.Ref_Number & "\Commercial"
Else
DoCmd.OutputTo acOutputReport, "OrderCustomerReport", acFormatPDF, filepath2
MsgBox "Quotation(v2) has been saved successfully", vbInformation, "Save Confirmed"
Application.FollowHyperlink "T:\ACCESS DATABASE\" & Me.Ref_Number & "\Commercial"
End If

Did I missed out anything?
Microsoft AccessVBA

Avatar of undefined
Last Comment
Ryan Chong
Avatar of Tusitala
Tusitala

Your summary doesn't explain much about your problem.

Is the filename the problem or the directory?
ASKER CERTIFIED SOLUTION
Avatar of Ryan Chong
Ryan Chong
Flag of Singapore image

Blurred text
THIS SOLUTION IS ONLY AVAILABLE TO MEMBERS.
View this solution by signing up for a free trial.
Members can start a 7-Day free trial and enjoy unlimited access to the platform.
See Pricing Options
Start Free Trial
You don't want vbdirectory in the Dir() call.

Remove it.

Jim
Avatar of Ryan Chong
Ryan Chong
Flag of Singapore image

If Dir("T:\ACCESS DATABASE\" & filename & "\Commercial\" & filename & " .pdf", vbDirectory) <> "" Then

Open in new window

can be amended to:

If Dir(filepath) = "" Then

Open in new window

Avatar of Ryan Chong
Ryan Chong
Flag of Singapore image

do you need further assistance here or we can proceed to close this question?
Avatar of Ryan Chong
Ryan Chong
Flag of Singapore image

Suggested solution should manage to resolve the issue.
Microsoft Access
Microsoft Access

Microsoft Access is a rapid application development (RAD) relational database tool. Access can be used for both desktop and web-based applications, and uses VBA (Visual Basic for Applications) as its coding language.

226K
Questions
--
Followers
--
Top Experts
Get a personalized solution from industry experts
Ask the experts
Read over 600 more reviews

TRUSTED BY

IBM logoIntel logoMicrosoft logoUbisoft logoSAP logo
Qualcomm logoCitrix Systems logoWorkday logoErnst & Young logo
High performer badgeUsers love us badge
LinkedIn logoFacebook logoX logoInstagram logoTikTok logoYouTube logo