OpenFile Dialog to add image path into database table (1 Viewer)

josephbupe

Registered User.
Local time
Today, 02:20
Joined
Jan 31, 2008
Messages
247
Hello everyone.

I have this code that I adapted for one of my projects years back to save images into a table but now I just cant get it to work. When I tried it this time, I was getting an error "The code in this project must be updated for use on 64-bit system", and so I found some suggestion to replace all Public and Private Declare statements with Declare PtrSafe in the module basOpenFile, which I did. But the OpenFile dialog is not being invoked through the button on the form.

I have attached the project file for assistance.

Joseph
 

Attachments

  • WORKS OF ART -3.accdb
    684 KB · Views: 213

isladogs

MVP / VIP
Local time
Today, 00:20
Joined
Jan 14, 2017
Messages
18,212
There are much better methods available now that don't require APIs and which work in both 32-bit & 64-bit Access.
Check out file dialog code. For example, see
 

josephbupe

Registered User.
Local time
Today, 02:20
Joined
Jan 31, 2008
Messages
247
There are much better methods available now that don't require APIs and which work in both 32-bit & 64-bit Access.
Check out file dialog code. For example, see
WOW! That's an interesting approach. But I also want to save information in a table for each photograph, and later add search facility to query the database.
 

isladogs

MVP / VIP
Local time
Today, 00:20
Joined
Jan 14, 2017
Messages
18,212
WOW! That's an interesting approach. But I also want to save information in a table for each photograph, and later add search facility to query the database.
That's exactly what that example is doing.
In the example, the file paths are overwritten when a new folder is selected.
However, that can easily be changed if you want to retain the file paths permanently
 

josephbupe

Registered User.
Local time
Today, 02:20
Joined
Jan 31, 2008
Messages
247
That's exactly what that example is doing.
In the example, the file paths are overwritten when a new folder is selected.
However, that can easily be changed if you want to retain the file paths permanently
Indeed! I see that now. OK, I will start from here. Thanks a lot.
 

josephbupe

Registered User.
Local time
Today, 02:20
Joined
Jan 31, 2008
Messages
247
That's exactly what that example is doing.
In the example, the file paths are overwritten when a new folder is selected.
However, that can easily be changed if you want to retain the file paths permanently
Hello isladogs.

I stumbled upon one of your code samples on how to properly save image path into a database table. Now I want the images folder and the split back-end data file within the project's path, so that it is portable. But I don't know how to do it.

Below is the code:

Code:
Private Sub cmdBrowse_Click()
 
On Error GoTo Err_Handler
 
'Code compatible with both 32-bit & 64-bit Office
 
' Set options for the file dialog box.
    Dim F As FileDialog
    Dim strFilePath As String
    Set F = Application.FileDialog(msoFileDialogFilePicker)
    F.title = "Locate the image file folder and click on 'Open' to select it"
 
' Clear out any current filters, and add our own
    F.Filters.Clear
    F.Filters.Add "Image files", "*.jpg;*.jpeg;*.png"
 
' Set the start folder. Open in default file folder if blank
    F.InitialFileName = Nz(Application.CurrentProject.Path & "\Images\", "C:\") 'modify this as appropriate
 
' Call the Open dialog procedure.
    F.Show
 
' Return the path and file name.
    strFilePath = F.SelectedItems(1)
    Me.ImagePath = strFilePath  'add the file path to a textbox on the form
 
Exit_Handler:
    Exit Sub
 
Err_Handler:
    If Err <> 5 Then 'err=5 user cancelled
        MsgBox "Error " & Err.Number & " in cmdBrowse_Click procedure: " & Err.Description
    End If
    Resume Exit_Handler
 
End Sub
 

theDBguy

I’m here to help
Staff member
Local time
Yesterday, 16:20
Joined
Oct 29, 2018
Messages
21,467
Hello isladogs.

I stumbled upon one of your code samples on how to properly save image path into a database table. Now I want the images folder and the split back-end data file within the project's path, so that it is portable. But I don't know how to do it.

Below is the code:

Code:
Private Sub cmdBrowse_Click()
 
On Error GoTo Err_Handler
 
'Code compatible with both 32-bit & 64-bit Office
 
' Set options for the file dialog box.
    Dim F As FileDialog
    Dim strFilePath As String
    Set F = Application.FileDialog(msoFileDialogFilePicker)
    F.title = "Locate the image file folder and click on 'Open' to select it"
 
' Clear out any current filters, and add our own
    F.Filters.Clear
    F.Filters.Add "Image files", "*.jpg;*.jpeg;*.png"
 
' Set the start folder. Open in default file folder if blank
    F.InitialFileName = Nz(Application.CurrentProject.Path & "\Images\", "C:\") 'modify this as appropriate
 
' Call the Open dialog procedure.
    F.Show
 
' Return the path and file name.
    strFilePath = F.SelectedItems(1)
    Me.ImagePath = strFilePath  'add the file path to a textbox on the form
 
Exit_Handler:
    Exit Sub
 
Err_Handler:
    If Err <> 5 Then 'err=5 user cancelled
        MsgBox "Error " & Err.Number & " in cmdBrowse_Click procedure: " & Err.Description
    End If
    Resume Exit_Handler
 
End Sub
Hi. To make a filepath "portable," you probably should just store the file's name instead of the full path. That way, you can add the folder location later, based on the current location of the database. In that case, this little article might be able to help.

 

isladogs

MVP / VIP
Local time
Today, 00:20
Joined
Jan 14, 2017
Messages
18,212
Just as @theDBguy suggested, I normally store the image file name in one table and store both the folder path & BE database path separately either in another table or as constants. Doing this saves repetition of data. You can then combine these as needed.
 

josephbupe

Registered User.
Local time
Today, 02:20
Joined
Jan 31, 2008
Messages
247
Just as @theDBguy suggested, I normally store the image file name in one table and store both the folder path & BE database path separately either in another table or as constants. Doing this saves repetition of data. You can then combine these as needed.
Oh yeah. Just not sure where to tweak that code and how to call the function. My bad!
 

josephbupe

Registered User.
Local time
Today, 02:20
Joined
Jan 31, 2008
Messages
247
Oh yeah. Just not sure where to tweak that code and how to call the function. My bad!
Ok. This is what I am doing now. Hopefully on the right track:

Code:
Dim relativePath As String

relativePath = "\Images\" & Me.txtObjectID & ".jpg"
Me!ImagePath.Value = relativePath

Thus far, I can see only the image named (i.e ObjectID) being populated into the table without the path. I hope I will get the rest done properly.

Thanks for your help.
 

Users who are viewing this thread

Top Bottom