Results 1 to 3 of 3
  1. #1
    mcracknell is offline Novice
    Windows 7 32bit Access 2010 32bit
    Join Date
    Jan 2013
    Posts
    2

    Displaying images from folder - Same Image on all records

    I am a novice at code and have used the MS guidance notes for displaying images (pictures) on a form from a folder outside of access. Having input the code its works, but I have a sub-form with mutiple records am trying to show multiple records with the relevant picture. Currently I get the same image (picture) on all the forms governed by whichever record im in within the subform. Is there a way of showing individual images?

    Code:
    Option Compare Database
    
    Option Explicit
    Public Function DisplayImage(ctlImageControl As Control, strImagePath As Variant) As String
    On Error GoTo Err_DisplayImage
    Dim strResult As String
    Dim strDatabasePath As String
    Dim intSlashLocation As Integer
    With ctlImageControl
        If IsNull(strImagePath) Then
            .Visible = False
            strResult = "No image name specified."
        Else
            If InStr(1, strImagePath, "\") = 0 Then
                ' Path is relative
                strDatabasePath = CurrentProject.FullName
                intSlashLocation = InStrRev(strDatabasePath, "\", Len(strDatabasePath))
                strDatabasePath = Left(strDatabasePath, intSlashLocation)
                strImagePath = strDatabasePath & strImagePath
            End If
            .Visible = True
            .Picture = strImagePath
            strResult = "Image found and displayed."
        End If
    End With
        
    Exit_DisplayImage:
        DisplayImage = strResult
        Exit Function
    Err_DisplayImage:
        Select Case Err.Number
            Case 2220       ' Can't find the picture.
                ctlImageControl.Visible = False
                strResult = "Can't find image in the specified name."
                Resume Exit_DisplayImage:
            Case Else       ' Some other error.
                MsgBox Err.Number & " " & Err.Description
                strResult = "An error occurred displaying image."
                Resume Exit_DisplayImage:
        End Select
    End Function
    Code:
    Option Compare Database
    
    Option Explicit
    Private Sub Form_AfterUpdate()
        CallDisplayImage
    End Sub
    Private Sub Form_Current()
        CallDisplayImage
    End Sub
    Private Sub txtImageName_AfterUpdate()
        CallDisplayImage
    End Sub
    Private Sub CallDisplayImage()
        Me!txtImageNote = DisplayImage(Me!ImageFrame, Me!txtImageName)
    End Sub
    Click image for larger version. 

Name:	Screenprint.png 
Views:	16 
Size:	129.5 KB 
ID:	10568

  2. #2
    June7's Avatar
    June7 is offline VIP
    Windows XP Access 2010 32bit
    Join Date
    May 2011
    Location
    The Great Land
    Posts
    53,770
    Is the image path/name saved in field of table? Use an Image control and set the ControlSource property. Virtually no code required. The ControlSource property was added to Image control with Access 2007.
    How to attach file: http://www.accessforums.net/showthread.php?t=70301 To provide db: copy, remove confidential data, run compact & repair, zip w/Windows Compression.

  3. #3
    mcracknell is offline Novice
    Windows 7 32bit Access 2010 32bit
    Join Date
    Jan 2013
    Posts
    2
    Excellent - Many thanks - That miakes things a lot easier

Please reply to this thread with any new information or opinions.

Similar Threads

  1. Replies: 8
    Last Post: 11-10-2012, 03:03 AM
  2. Replies: 1
    Last Post: 10-05-2012, 08:28 PM
  3. Displaying bound images in a form
    By munroe47 in forum Forms
    Replies: 5
    Last Post: 07-10-2012, 06:18 PM
  4. Replies: 1
    Last Post: 02-13-2012, 06:18 AM
  5. Displaying images from another folder
    By w3leon in forum Access
    Replies: 0
    Last Post: 01-30-2009, 06:18 PM

Tags for this Thread

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts
  •  
Other Forums: Microsoft Office Forums