Yet another Insert Image thread

airman

Registered User.
Local time
Today, 05:41
Joined
Mar 10, 2005
Messages
11
Hello,
Although, I have seen many threads in regards to displaying images in forms, I have not been able to find exactly what I'm looking for.

The solution I am looking for is to give the user the ability to browse for an image, select it and insert it into the form. From reading these forums and playing around with Access, one thign I am sure about is that I want to link the image (I couldn't believe how bloated access gets when embedding an image).

I thought of a great solution for linking images, but I have no idea how to achieve this. (This solution, in my opinion would be great not just for images, but for all kind of objects).

Since I am linking the image, I would like to be able to store the image in a "private database" folder, that way the image will not be tempered with. It is my understanding that if I wanted to do that, I would have to first place the images in that folder and then actualy insert them into the form. This seems kind of pointless to me, since it will create extra work for the user.

So basically what I would like to do in pseudo code is:

On Click, browse for image
on image select, save image to \\database image folder
link image to \\data image folder
display image in form


I think this would work really well for all kinds of document management (not just images) allowing the users to attach pdfs/images/documents to records with out worrying where they are stored, and knowing they will not be tempered with (I'm planning to place the folder somewhere on the server)]

Any ways, any help woudl be greatly appreciated, and if I do manage to come up with a solution on my own, I will be sure to post it here.
 
Five years later I had the exact same challenge and this is one of the first threads that popped up when I searched for help.

I will attach my code for solving this problem... I hope it is pretty self explanatory.

Code:
Private Sub DeleteImageButton_Click()
On Error GoTo ErrorCode
    
    [HasImage] = False
    Kill CurrentPicturePath()
    Call RefreshImage

ExitCode:
    Exit Sub
ErrorCode:
    MsgBox "Error " & Err.Number & vbNewLine & " " & Err.Description
    Resume ExitCode
End Sub

Private Sub Form_Current()
On Error GoTo ErrorCode
            
    Call RefreshImage

ExitCode:
    Exit Sub
ErrorCode:
    MsgBox "Error " & Err.Number & vbNewLine & " " & Err.Description
    Resume ExitCode
End Sub

Private Sub SelectImageButton_Click()
'opendialogbox
    Set fd = Application.FileDialog(msoFileDialogFilePicker)
    fd.AllowMultiSelect = False
    fd.Title = "Select a picture file in JPEG format"
    fd.Filters.Clear
    fd.Filters.Add "JPEG Images", "*.jpg; *.jpeg", 1
    doit = fd.Show
    If (doit) Then
        [HasImage] = True  'mostly just to make the ID show up
        filepathorig = fd.SelectedItems(1)
        filepathnew = CurrentPicturePath()
        FileCopy filepathorig, filepathnew
        Call RefreshImage
    End If
    
End Sub

Private Sub RefreshImage()
    On Error GoTo ErrorCode
                
    If Dir(CurrentPicturePath()) = "" Then
        'MsgBox "the file doesn't exist"
        Me.Image6.Picture = ""
    Else
        Me.Image6.Picture = CurrentPicturePath()
    End If

ExitCode:
    Exit Sub
ErrorCode:
    MsgBox "Error " & Err.Number & vbNewLine & " " & Err.Description
    Resume ExitCode

End Sub

Private Function CurrentPicturePath() As String
    CurrentPicturePath = CurrentProject.Path & "\database1 photos\" & "HSEDB_" & [ID] & ".jpg"
End Function
 

Users who are viewing this thread

Back
Top Bottom