how to set the path

rexb

Registered User.
Local time
Today, 07:57
Joined
Oct 29, 2008
Messages
129
Hello,

I have a form where i get to insert files (images, doc, pdf, excel, ppt files). I am able to load it to the form and display it. Right now it displays the whole path of the file. My question is... Is there a way to save the path but not specific to the drive just the folder where it is saved. why because this database is on a flash drive so pretty much if it is used on one computer the drive name might not be the same drive name assignment on another computer.
 
I currently do this is some of my apps, but it does require some VBA coding.

The easiest method I have found is to replace the main folder where the files are located with something like "%dir%" for the path would be "%dir%\docs\myfile.pdf". I use the Replace function to replace the %dir% with the current location before trying to open the file.
 
I currently do this is some of my apps, but it does require some VBA coding.

The easiest method I have found is to replace the main folder where the files are located with something like "%dir%" for the path would be "%dir%\docs\myfile.pdf". I use the Replace function to replace the %dir% with the current location before trying to open the file.


do you have any sample of these sort of database? I am just new to programming and I'm having some problem placing it on the right spot.
 
It really is just using the Replace() function before you store the path and after you read the path.


Example to view the file using the Replace():

Code:
   strFilePath = "%dir%\myfile.gif"

   strRoot = "\\server\sharename"
    
   strPath = Replace(strFilePath, "%dir%", strRoot)

   ' place code here to view the file located in strPath

The variable strPath will hold the path of the file to view/open

Code:
Print strPath
\\server\sharename\%dir%\myfile.gif
 
It really is just using the Replace() function before you store the path and after you read the path.


Example to view the file using the Replace():

Code:
   strFilePath = "%dir%\myfile.gif"

   strRoot = "\\server\sharename"
    
   strPath = Replace(strFilePath, "%dir%", strRoot)

   ' place code here to view the file located in strPath
The variable strPath will hold the path of the file to view/open

Code:
Print strPath
\\server\sharename\%dir%\myfile.gif


With the present code that I have I don't think I'll be able to do that(wouldn't know where to insert on the code). So I've attached my entry form. If you could show me how to do the code for file insert I would very much appreciate it. Pretty much the idea is when the user click on floor plan or lease contract or building photo the user will be directed to the right folder (e.g. floorplan folder, leascecontract folder, buildingphoto folder). And then again this would be placed on a flash drive so assigning a drive would not be reasonable becuase as i've said it is on a flash drive and once it is moved to another computer the drive path could be different. I'm really at a lost on the coding so if you/anybody could help out I would very much appreciate it.
 

Attachments

  • form.JPG
    form.JPG
    84.9 KB · Views: 192
Unfortunately, The image of the screen does not really help because we can not see any of the VBA code behind the form.

How are you getting the path to a file into the field in the table? What VBA code are you using?

What VBA code are you using to view the file?
 
Unfortunately, The image of the screen does not really help because we can not see any of the VBA code behind the form.

How are you getting the path to a file into the field in the table? What VBA code are you using?

What VBA code are you using to view the file?


can't we just create a code from scratch? if not i'll try to attach the database
 
can't we just create a code from scratch? if not i'll try to attach the database

Sure, I can help you write the code from scratch.

Displaying the file is easy. I would use the ShellExec Windows API.

Storing the path to the file you want to attach will take a little more work. Do you want to use the standard Windows Dialog to select the file or some other method?

If you want to use the standard Windows Dialog to select the file like this example: Document Links I could create a working example for you based on this. Would that help?
 
Sure, I can help you write the code from scratch.

Displaying the file is easy. I would use the ShellExec Windows API.

Storing the path to the file you want to attach will take a little more work. Do you want to use the standard Windows Dialog to select the file or some other method?

If you want to use the standard Windows Dialog to select the file like this example: Document Links I could create a working example for you based on this. Would that help?

as long as we get it to work from a stand point of using it on a flash drive
thanks
 
Not sure if you said if you have a preference on how the file path gets into the table?

Did you look at the example? Will that method work?
 
Not sure if you said if you have a preference on how the file path gets into the table?

Did you look at the example? Will that method work?


I looked at it and it says it could save the path. but lets say I have the access database on a save folder say "folder1" and inside this folder1 i have the following folders 1) "floorplan" 2)"leasecontract" and 3) "buildingphoto" so all the files pertaining to each would be save on these folders that part the example you showed me would be able to do that. now let say this folder1 which contains 3 subfolders is on a flash drive. It would save the existing path with respect to the drive letter it is currently save at right? if this is so, wouldn't i have a problem when the database from folder1 is move to another computer and the drive letter might or could be different with respect to the save file on the database right. this is my problem how do I make that database just look at folder1 and not at the drive letter? because if it looks at the letter it could be different.
 
I am trying to create an example for you, but I never really do anything "from scratch" since it can be very time consuming. I have lots of code libraries and base databases that I use as a starting point. I am just trying to identify if I have something very close to what you need that could easily be modified to do what you want.

The example I had you look at stores a fixed path. It was just to show you a method for selecting a file, not the way to store the file path data. Nothing more. If this method of selecting the file will work for you, I will update the example to handle the path as I suggested in my previous replies where the full path is not stored. This will allow the folder with the linked files to be moved to a different location. I currently use this method for document management systems when the data is stored on a network and the data needs to be able to be relocated.
 
If your DB runs of the same flash drive... Currentdb.Name will return the full path of your DB, including the drive name...

Does that help you?
 
Hi!
i am a new user of this forum and i have a some problem regarding some assignement given my boss, basiscally i am working in one of food chain restaurant and my boss asked me to prepare the file of costing which should have a link of receipes and when we put the sold item of menu and it autimatically show the consumpiton of each raw material.
Do you have any idea i personally appreciate your thinking.i am very thankfull for you.

Rgds

chacha
 
I am trying to create an example for you, but I never really do anything "from scratch" since it can be very time consuming. I have lots of code libraries and base databases that I use as a starting point. I am just trying to identify if I have something very close to what you need that could easily be modified to do what you want.

The example I had you look at stores a fixed path. It was just to show you a method for selecting a file, not the way to store the file path data. Nothing more. If this method of selecting the file will work for you, I will update the example to handle the path as I suggested in my previous replies where the full path is not stored. This will allow the folder with the linked files to be moved to a different location. I currently use this method for document management systems when the data is stored on a network and the data needs to be able to be relocated.


I appreciate your help very much and for being patience with me. Actually those are the codes I have on my database so I should just send my database to you so you can modify it to suit my needs.
 

Attachments

I tried to run your example that you posted but it gets lots of missing reference errors.

I am modifying my example for you. I will post it when it it ready.
 
If your DB runs of the same flash drive... Currentdb.Name will return the full path of your DB, including the drive name...

Does that help you?

How nice it is to be completly ignored :(
 
How nice it is to be completly ignored :(

namliam,

Sorry. :eek: Did not mean to ignore you.

Yes, your suggestion may be helpful, but the problem is in the understanding how/where to use it by the OP.

Unfortunately, the linked files may need to be in sub folders that are NOT in the same location as the database. I think your suggestion would require that. I am trying to make it as flexible as possible to handle any future needs of the OP and as many others as possible with the same code.
 
Last edited:
How nice it is to be completly ignored :(

I found that when creating my example and trying to use your suggestion, that using CurrentProject.Path was easy to use than Currentdb.Name because it already had just the path and I did not have to strip of the database name off the end id I use Currentdb.Name.
 
Last edited:

Users who are viewing this thread

Back
Top Bottom