Question Button

Workflow

Registered User.
Local time
Today, 04:39
Joined
Oct 31, 2014
Messages
31
Hi
thanks for the replies on my last query, (even though I didnt manage to solve my problem :( ).

Today I was hoping someone could help me to create a button to open a file.

I am using Access 2010 and a database for my catalogue, I have a field for an attachment which shows the image fine. I would like to be able to hit a button that opens the file in either the default windows program for that extension (in this case its a jpg) or maybe any program I can choose, so say Photoshop, Corel Draw or Windows Picture Viewer.

Hope you can help me

Kind regards

Nick
 
The easy way is to use the default application is something like

Code:
Sub cmdOpenFileButton_OnCLick

application.followhyperlink me.FieldWithFullPathToFile

As this doesn't need anything other than an association to work.
 
Hi Minty

I think I follow what you are saying, but the full path to the file is stored in the attachment field can I someone associate that when it is looking for a file to open, I have 2000 pictures in the db and wish to make it loads more, i dont fancy typing in the full path each time which looks like this R:\xxxxxxx-xxxxxx\Catalogue\20 - Animals\200 - Birds\20001 - Bald Eagle in Flight, Alaska (2).jpg.

Also when the file name goes in it misses out the R: and puts 2 dots in its place (..) then it wont open the file I have to manually change it.

thanks

Nick
 
Ah well you don't need to store the full path, just the bits that change per picture.
Looking at the link you posted you would store the first part as a variable

defaultPath = "r:\xxxxxxxxxx-xxxxxxxxxxx\catalogue"

Then build the rest of it from what you've stored that locates it.
I'm guessing from the path structure that your path can be calculated or is pulled from a drop down list?
 
I think I dont explain things very well, so I wil start again

Access 2010, I have a database for a catalogue of 2000 pictures, mainly jpgs but some others aswell.

On a form I want to be able to see the picture and then if I need to say edit it or look at it more closely or print then I would like a button that opens it in either the default windows viewer or a specified program such as photoshop.

At the moment I have a attatchment field which shows the picture on the form ok but then I have no way to do anything wlse with it.

Hope this is written better.

thanks

Nick
 
It was very clear at first time.

If you can show the file you must have its full path and name
Whats not working with what Minty gave you ?
 
I have this as code

Sub cmdOpenFileButton_OnCLick()

Application.FollowHyperlink Me.[File]

End Sub

Private Sub Open_File_Click()

End Sub

where [File] is the field that is storing the file name, including the path

when I press the button nothing happens

thanks

Nick
 
What is your command button called - I suspect it is Open_File ?

Oh and change the field name from File - that will cause you no end of confusion and problems further into the development. Do it now before it's too late!
 
Using File as text box name is not recommanded.
Try without the square brackets.
 
What is your command button called - I suspect it is Open_File ?

Oh and change the field name from File - that will cause you no end of confusion and problems further into the development. Do it now before it's too late!

Hi, thank you for replying, the button is called - Open File.

The field name is File because that is the information stored there, am I missing something here?

Kind regards

Nick
 
Using File as text box name is not recommanded.
Try without the square brackets.

Hi thanks for replying

I have now tried it with and without the sqaure brackets and it still doesnt work

Kind regards

Nick
 
Okay - back to basics. When you click the event builder on your button it is showing you this;
Code:
Private Sub Open_File_Click()

End Sub

You need to add the code I showed you earlier to this event;

Code:
Private Sub Open_File_Click()

Application.FollowHyperlink Me.[File]

End Sub

The reason you shouldn't call a field or control or anything else File is that that is a reserved name in Access, and will mean you always have to enclose it in square brackets. Changing it will simply make your life easier and in future your code a lot easier to read and debug. Call it txtFilePath or something similar.

I would also call your button something without spaces - spaces in control names make life more difficult as well in future.

See this excellent link about naming things in access; http://www.access-programmers.co.uk/forums/showthread.php?t=225837
 
I have two types of addresses in the field "File" (WILL RENAME LATER), some records show it as

R:\blah blah blah and in others it shows as ..\blah blah

when I click the button now it first comes up with a message that shows

"A potential security concern has been identified
This location may be unsafe
Hyperlinks can be harmful to your computer and data. To protect
your computer, click only those hyperlinks from trusted sources.

Do you want to continue?

YES NO "

choosing no obvioulsy closes the dialog box and thats it if I choose Yes

Sometimes it says

"Windows cannot find
.....****CORRECT FILE NAME****....
Make sure you typed the name correctly , and then try again"

and sometimes it says

"Run-time error '7971'

MS Access cannot follow the hyperlink to ...***CORRECT FILE NAME***...

END or DEBUG

Any one know whats happening please?

kind regards

Nick
 
Firstly - You need to add the file location to the list of trusted sites, that should remove the security message.

Secondly, if you cut and paste the file name as you have it stored in the database into windows explorer what happens ?
 
thanks for the qucik reply Minty,

If I copy and paste the file name in explorer it shows me the picture.

Not sure how to add a trusted site but I will sort that one out.

thankseversomuch for your help

Kind regards

Nick
 
Hi

I found the trust center and added all the locations on the network, and checked all the right boxes and saved, closed and re-opened the database, but I am still getting the same trust message.

any ideas?

kind regards

Nick
 

Users who are viewing this thread

Back
Top Bottom