one relative linked image per record (1 Viewer)

Status
Not open for further replies.

wiklendt

i recommend chocolate
Local time
Today, 10:53
Joined
Mar 10, 2008
Messages
1,746
this is DB shows a basic method of managing a relatively linked image for each record, such as an employee image for each employee.

it features:


  • an add image button
  • a remove image button (does not delete image fom computer)
  • a default "no image" image
  • once added, code copies the image from the source path to an existing subfolder of the DB, and renames the file to match the primary key of the record it is being associated with.
  • stores the relative path of the image, not the image itself, in a table
the upshot of these last two features is that the image can be found from any source (e.g., USB drive), and still be available to the DB even if that original source is subsequently removed or deleted AND keeps these files tidy.

it draws on code collected from various other image samples and posts in access world forums (including lots of help from CyberLinx, thank you muchly), as i found that not any one sample DB did EVERYthing i wanted. as such, i don't expect MY version will do EVERYthing YOU want it to do, it's just a nice little package which you can kick-start your DB with (and that suited MY needs at the time i put it together).

if anyone has improvement suggestions, i'll be very happy to hear them. like-wise, if you have criticisms please make them constructive.

this database has NOT been tested on a server or LAN environemnt, and has NOT been tested as in a split DB situation. if you require these features, please first just TRY them, research the appropriate way to do it, then post any questions in the appropriate section of the forum if you are still having troubles (you are not allowed to post questions in the "sample databases" forum).

hope this helps
 

Attachments

  • ImagePerRecord Wiklendt.zip
    399.4 KB · Views: 2,189

wiklendt

i recommend chocolate
Local time
Today, 10:53
Joined
Mar 10, 2008
Messages
1,746
update: delete file when removing image

I have been asked how to delete the image file when removing the image from a record. In fact, this should probably be default because when adding an image, the original file is copied to the subfolder of the DB, so when removing, it is ok to delete this copy, making the DB image folder size at a minimum (hence easier to transfer if ever needed).

to remove the file itself, the command "Kill" is given, followed by the file path.

i've also adjusted the message given to the user - this can be changed if you want to (e.g., to just "Remove image?").

please find the adjusted code below (given in red) with the adjustments made in the attachment of THIS post.

Code:
Private Sub cmdImg_Remove_Click()

On Error GoTo Err_cmdImg_Remove_Click

    Dim Msg, Msg2, Style, Style2, Title, Response
    Dim dbPath
    
    dbPath = Application.CurrentProject.Path
    
    ' save the current image in case user changes mind
    OriginalImagePath = Me!Image

    ' set the variables for the message boxes
    Msg = [COLOR=Red]"Remove image?" & Chr(13) & Chr(13) & "Will delete file: " & Chr(13) & Chr(13) & dbPath & OriginalImagePath[/COLOR]
    Style = vbYesNo + vbQuestion + vbDefaultButton2
    Msg2 = "No image to remove"
    Style2 = vbOKOnly + vbInformation
    Title = "Bacterial Pathogenesis"
    
    ' make sure there is a photo there to remove
    If IsNull(Me!Image) Then
        ' no photo exists, so let the user know one cannot be removed
        MsgBox Msg2, Style2, Title
    Else
        ' a photo exists, so ask whether user is sure
        Response = MsgBox(Msg, Style, Title)
    
       If Response = vbYes Then
           ' user wants to remove, so remove photo
           Me![Image] = ""
           Me!imgPersonnel.Picture = ""
           [COLOR=Red]Kill (dbPath & OriginalImagePath)[/COLOR]
       Else
           ' user wants to keep, so restore originial
           Me![Image] = OriginalImagePath
           Me!imgPersonnel.Picture = dbPath & Me![Image]
       End If
    End If

Exit_cmdImg_Remove_Click:
    Exit Sub

Err_cmdImg_Remove_Click:
        Msg = "Error # " & Str(Err.Number) & Chr(13) & Err.Description
        MsgBox Msg, vbOKOnly, "Bacterial Pathogenesis", Err.HelpFile, Err.HelpContext
    Resume Exit_cmdImg_Remove_Click
    
End Sub
 

Attachments

  • ImagePerRecord Wiklendt (2).zip
    342.8 KB · Views: 966
Status
Not open for further replies.

Users who are viewing this thread

Top Bottom