Using images in an access database (1 Viewer)

kobiashi

Registered User.
Local time
Today, 21:57
Joined
May 11, 2018
Messages
258
Hi

I am currently setting up an access database for my work, and i have noticed the file size get larger, and i can only assume its due to images being stored as attachments.

i have tried to search for a guide or some kind of tutorial on storing images in a folder, but im not having much luck, could someone point me in the direction to some content on it please.
 

kobiashi

Registered User.
Local time
Today, 21:57
Joined
May 11, 2018
Messages
258
What is wrong with the method that Bastanu showed you in this thread.?


https://access-programmers.co.uk/forums/showthread.php?t=299756

Nothing wrong with the method, that works, perfectly.

But i dont understand how to store and manage images in a database by saving the file path, so i need to learn more, about, but i cannot find any information on it, maybe im not using the correct search criteria.

for example

how do users add the file path, do they choose the file via pop up window?

if so, what happens to that image, is it stored in a folder, or does it stay in the original location, if so , what happens if someone deletes it?
 

Gasman

Enthusiastic Amateur
Local time
Today, 21:57
Joined
Sep 21, 2011
Messages
14,047
Yes, I would go for selecting the file via a popup window.
I would allow the user to select the file, perhaps check the extension for known/wanted file types and copy it to a safe location and allow for deletion via the database.


Search for FileDialog in these forums.

Here is a snippet that I created to get the user to select a file for import. It is run from the click event of a button and shows the full path in textbox. You would store that value in a table as Bastanu did.? Code highlighted in Red

This code is mainly for me to use, so not bulletproof or idiotproof. :D



Code:
Private Sub cmdSelect_Click()
Dim fDialog As Office.FileDialog
Dim varFile As Variant
Dim strPath As String

' Set up the File Dialog. '
 Set fDialog = Application.FileDialog(msoFileDialogFilePicker)

' Set default path which is users download folder
strPath = GetDownloadsFolder()

' Disable sunform in case form left enabled from a previous run.
Me.sfrmBankStatement.Form.AllowEdits = False

With fDialog

    ' Allow user to make multiple selections in dialog box '
    .AllowMultiSelect = False
    
    ' Set the title of the dialog box. '
    .Title = "Please select Bank Statement downloaded file"
    
    ' Clear out the current filters, and add our own.'
    .Filters.Clear
    .Filters.Add "CSV files", "*.csv"
    
    .InitialFileName = strPath
    ' Show the dialog box. If the .Show method returns True, the '
    ' user picked at least one file. If the .Show method returns '
    ' False, the user clicked Cancel. '
    If .Show = True Then
       [COLOR=Red] Me.txtFilename = .SelectedItems(1)[/COLOR]
    Else
       MsgBox "You must select a filename!"
       Me.txtFilename = ""
       Exit Sub
    End If
End With

' Now get that data
DoCmd.SetWarnings False
SetStatusBar ("Deleting old data .....")
DoCmd.RunSQL "DELETE * from TesttblBankStatement"
SetStatusBar ("Importing selected data")
DoCmd.TransferText acImportDelim, "Bank Statement Import Specification", "TesttblBankStatement", Me.txtFilename, True
DoCmd.SetWarnings False
SetStatusBar (" ")

' Now enable subform if file selected
Me.sfrmBankStatement.Form.AllowEdits = True
Me.sfrmBankStatement.Form.Requery
End Sub
HTH
 

kobiashi

Registered User.
Local time
Today, 21:57
Joined
May 11, 2018
Messages
258
thanks for the code, and info, it has helped with my search, but im still struggling to understand where the images will be stored.

Are they stored in a specified folder, or do they stay in the location specified by the user, if so what happens when the user deletes the image?
 

Gasman

Enthusiastic Amateur
Local time
Today, 21:57
Joined
Sep 21, 2011
Messages
14,047
I personally would copy them to a location (even hidden) once the user selects the image. If they want to delete it, it is done via the DB, not explorer. If they want to replace it, they use the same process.
You might want to delete the old one afterwards, but one thing at a time. :D
 

Users who are viewing this thread

Top Bottom