Adding Relative Image Paths using FileDialog

philwickens

New member
Local time
Today, 04:24
Joined
Jan 3, 2006
Messages
5
I am trying to add a relative image path (i.e. just the filename and extension) to a database field. Using the the following code that comes with the Northwind database I can only store the full image path. Can anyone help?

Sub getFileName()
Dim fileName As String
Dim result As Integer
With Application.FileDialog(msoFileDialogFilePicker)
.Title = "Select Employee Picture"
.Filters.Add "All Files", "*.*"
.Filters.Add "JPEGs", "*.jpg"
.Filters.Add "Bitmaps", "*.bmp"
.FilterIndex = 1
.AllowMultiSelect = False
.InitialFileName = CurrentProject.path & "\Images_Contacts"
result = .Show
If (result <> 0) Then
fileName = Trim(.SelectedItems.Item(1))
Me![ImagePath].Visible = True
Me![ImagePath].SetFocus
Me![ImagePath].Text = fileName
Me![FirstName].SetFocus
Me![ImagePath].Visible = False
End If
End With
End Sub
 
Last edited:
Code:
Dim fileNm as String
fileNm = Right(fileName, Len(fileName) - InStrRev(fileName, "\"))

' Input: c:\program files\someprogram\mypic.bmp
' Output: mypic.bmp

I hope this helps.
 
You might try modifying the following line:
Code:
fileName = Trim(.SelectedItems.Item(1))
...to...
Code:
fileName = [b]Dir([/b]Trim(.SelectedItems.Item(1))[b])[/b]

See if this works for you.
 
Cheers for the replies - I have tried both and they both do the job. Many thanks!
 

Users who are viewing this thread

Back
Top Bottom