Solved Opening document without full Path (1 Viewer)

stu_c

Registered User.
Local time
Today, 21:57
Joined
Sep 20, 2007
Messages
489
Hi all
I am currently using the below code to open a document
Code:
    Set oWd = CreateObject("Word.Application")
    Set oDoc = oWd.Documents.Add("C:\Users\Databases\HRRecords\Reports\HRReportFile.docx")

Is there a way to only get access to search for the document within the main folder path rather than the whole CDrive, for example I know with HTML etc you can put ../ etc, the issue I have is if the database gets moved to another drive then I need to manually change the file path so it still looks for it in the correct place? if it cannot be done its not a big issue

Example of how I mean
Code:
    Set oWd = CreateObject("Word.Application")
    Set oDoc = oWd.Documents.Add("..\Reports\HRReportFile.docx")
 
Last edited:

Gasman

Enthusiastic Amateur
Local time
Today, 21:57
Joined
Sep 21, 2011
Messages
14,317
Why would you open an excel file with Word?
 

KitaYama

Well-known member
Local time
Tomorrow, 05:57
Joined
Jan 6, 2022
Messages
1,541
I always use

CurrentProject.Path

So in your case it should be something like :

Set oDoc = oWd.Documents.Add(CurrentProject.Path & "\Reports\HRReportFile.docx")
 

stu_c

Registered User.
Local time
Today, 21:57
Joined
Sep 20, 2007
Messages
489
I always use

CurrentProject.Path

So in your case it should be something like :

Set oDoc = oWd.Documents.Add(CurrentProject.Path & "\Reports\HRReportFile.docx")
thank you!
 

Pat Hartman

Super Moderator
Staff member
Local time
Today, 16:57
Joined
Feb 19, 2002
Messages
43,299
If the documents are in shared folders on the server, keep a table with the paths in the BE. The part of the path you store is dependent on your app. I have some where I keep only the high level path. Each client has a subfolder and that part of the path is in the client record. Then there are hard-coded sub paths between client and the document. For others, I keep a doctype and so each doctype has a specific folder. Other cases, the folders are controlled by the users and so the table has to include the UserID so each user can store his own paths.
 

Users who are viewing this thread

Top Bottom