Tek-Tips is the largest IT community on the Internet today!

Members share and learn making Tek-Tips Forums the best source of peer-reviewed technical information on the Internet!

  • Congratulations TouchToneTommy on being selected by the Tek-Tips community for having the most helpful posts in the forums last week. Way to Go!

MS Access - Images & Pathnames 2

Status
Not open for further replies.

keiem

Technical User
Aug 1, 2001
27
US
I have individual images for each record in my access database that are displayed on a form. Is there a way to avoid using a full pathname pointing to the images? I want to dump the whole database (including associated images) on a CD, which will then be distributed for use on other standalone workstations running Access. Is there a way to designate a generic pathname for the image directories on the CD without giving a specific driveletter, etc? (i.e., "../dirname/filename" or "~/dirname/filename)? So far I haven't come across any syntax that MS Access will recognize. Help!

 
Use the Currentdb() function to acquire the current path of the database. Like this...

Currentdb.Name

Returns something like: "C:\My Documents\MyDb.mdb"

In code, you can extract the path and apply it to your pics.
This will work as long as you place your pics in a consistent folder relative to your MDB/MDE.

Gary
gwinn7
 
Thanks! That sounds like its exactly the type of thing I'm looking for. I'm new to Visual Basic programming, however, so could someone give me advice on how this might be enacted in the code? My existing code for the image insertion on my form is as follows.

Private Sub Form_Current()
On Error Resume Next
Me![ImageFrame].Picture = Me![PHOTO_FILENAME]
End Sub

PHOTO_FILENAME is the field in which the image filename (duh!) is stored. I'm primarily interested in the code required to extract the pathname from the Currentdb.Name function and then combining it with the inputed filename from PHOTO_FILENAME. Thanks again for all the help!
 
Not a problem. I think there is a simpler method through a recursive function, but this one should work fine.

Public Function ParsePath(FullPath As String) As String

Dim i As Integer
Dim tstring As String

On Error GoTo Handler:

i = Len(FullPath)

Do Until (tstring = "\" Or i = 0)

tstring = Mid(FullPath, i, 1)
i = i - 1

Loop

If i = 0 Then
ParsePath = ""
Else
ParsePath = Left(FullPath, i)
End If

Exit Function

Handler:
ParsePath = ""
Exit Function

End Function

Gary
gwinn7
 
I really appreciate all your help and I think I know whats going on... However, I have a couple questions.

1. Am I supposed to use the code you provided instead of the Currentdb() function? And if so,
2. How do I change my existing code for the ImageFrame and PHOTOFILENAME to implement this new information? I'm assuming that the string "ParsePath" contains the needed pathname and must be somehow combined with PHOTO_FILENAME in my Sub.

If my assumptions are incorrect, could you show me how your code relates to Currentdb() in addition to answering question #2?

Thanks!
 
gwinns's nifty function returns the path to your DB except the name of the file. It can be a little confusing though, this function business. When you write the function, say in a public module, you do it exactly as gw wrote it. When you call the function, it looks something like this:
DbPath = CurrentDB.Name
PhotoPath = ParsePath(DbPath) & "PhotoFileName"
 
Okay, I think I understand what I'm doing now and have formulated some code. It still isn't working, however. Could someone check this to see if its correct? I placed Gary's Public ParsePath() function into the form code and added the following sub per AArt's suggestion:

Private Sub Form_Current()

On Error Resume Next

Dim DbPath As String
Dim ImagePath As String
Dim ShortPath As String

DbPath = CurrentDb.Name
ShortPath = ParsePath(DbPath)
ImagePath = "ShortPath" & Me![PHOTO_FILENAME]

If IsNull(Me![PHOTO_FILENAME]) Then
Me![ImageFrame].Picture = "ShortPath" & "noimage.jpg"
Else: Me![ImageFrame].Picture = "ImagePath"

End If

End Sub

Any thoughts??
 
The first obvious problem is to remove the quotations surrounding your variables, like "ShortPath".

For example, this code...

ImagePath = "ShortPath" & Me![PHOTO_FILENAME]

...should actually read...

ImagePath = ShortPath & Me![PHOTO_FILENAME]

Placing quotations around a variable or value returns the literal value between the quotations, not the value the variable represents.

You may also need to include a literal "\" in between the ShortPath variable and the Photo filename.

Gary
gwinn7

 
Gary - That did it. Thanks SO much!!

I should have known about the quotes around variables, but I would've totally missed the "\". Thanks for all your help. The parse code was invaluable!
 
You are welcome! Good to see your follow-up message!

Gary
gwinn7

 
Status
Not open for further replies.

Part and Inventory Search

Sponsor

Back
Top