Adding Button on Form, field value as file locator.

  • Thread starter Thread starter JoeHawk
  • Start date Start date
J

JoeHawk

Guest
One of the fields in our form is the Assessor’s Parcel Number “(APN)” which is a unique number for a piece of real property. The value in this field is always a nine digit number.

Outside of Access we have a folder in My Documents which represents each county, and within this folder we have Jpeg files which are named by the "APN#.jpg" Example: C:\My Documents\Riverside County\123456789.jpg
This Jpeg would be the photograph of the house which is located on APN 123456789.

I would like to add a button on the form which would start my jpg viewer and pull up the specific jpeg file by looking into the APN field to find the file name.

I have no experience in writing any code for Access 2000, so I would appreciate some description on each line of code. Thanks

[This message has been edited by JoeHawk (edited 03-06-2002).]
 
I'm not sure if the response you helped me with is a workable one for me. I do not have access to change the data table to add a path to a picture.

Is there code that when I click on the button is in effect the same as .. double clicking on ... C:\My Documents\Riverside County\[APN].jpg? Where [APN] is the data in the field of the subject record?
 
This works for me in Access97 (I have no idea about Access2000):

I think the command you are looking for is the 'Shell' function that starts another application here's an example (I assume you have a field called [County] specifying the county name of each APN, if not I think you've got problems):

----
Dim FilePath as String
Dim ViewerPath as String
Dim TotalPath as String

FilePath = "C:\My Documents\" & Me.[County] & "\" & Me.[APN] & ".jpg" 'Sets the path to the jpeg file.
ViewerPath = "C:\YourViewerPathHere\YourViewer.exe" 'Sets the path to the executable of the viewer you want to use.

TotalPath = ViewerPath & " " & FilePath ' Creates .exe path plus file to open.

Call Shell(TotalPath, vbMaximizedFocus) 'Starts your Viewer program with the requested jpeg file

----

See the help on Shell for other options apart form the 'vbMaximizedFocus' used above.
Note, the above code lacks any error trapping for non-existent files etc.

Hope this is of help.
 
Whoops, forgot to mention that I've had problems if the FilePath string contains <spaces>. I don't know how to get around that one though, sorry.
 
I may be wrong but I think that you can deal with spaces by enclosing the string into double quotes.
Someting like:
FilePath = """" & "C:\My Documents\" & Me.[County] & "\" & Me.[APN] & ".jpg" & """"

Alex
 
Yea! Got it working. Just wanted to thank each person that responded. So far a little bit of each response was used to write and debug the code.
 

Users who are viewing this thread

Back
Top Bottom