Results 1 to 3 of 3
  1. #1
    Baja GEary is offline Novice
    Windows 7 32bit Access 2003
    Join Date
    Feb 2018
    Posts
    1

    inserting pictures in form problem with code

    Form: frmImage
    ----------------------
    Caption: Image Form
    RecordSource: tblImage

    Image Control
    ---------------------------------
    Name: ImageFrame
    Picture: "C:\Windows\Zapotec.bmp"

    Text box
    ----------------------
    Name: txtImageID
    ControlSource: ImageID

    Text box
    ---------------------------
    Name: txtImageName
    ControlSource: txtImageName

    Text box
    ---------------------------
    Name: txtImageNote
    ControlSource: <Blank>

    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
    Last edited by Baja GEary; 02-23-2018 at 11:35 AM. Reason: code does not bring pictures to form

  2. #2
    isladogs's Avatar
    isladogs is offline MVP / VIP
    Windows 10 Access 2010 32bit
    Join Date
    Jan 2014
    Location
    Somerset, UK
    Posts
    5,954
    This looks like standard but fairly old demo code from Microsoft
    Apart from the reason given in the edit, it's not obvious why you posted this code.
    If you are expecting to show the zapotec.bmp file, this is no longer included with recent versions of Windows.

    If you want it to show other files, what code are you using to do so and what does happen?
    Colin, Access MVP, Website, email
    The more I learn, the more I know I don't know. When I don't know, I keep quiet!
    If I don't know that I don't know, I don't know whether to answer

  3. #3
    June7's Avatar
    June7 is offline VIP
    Windows 10 Access 2010 32bit
    Join Date
    May 2011
    Location
    The Great Land
    Posts
    52,815
    Why use VBA code to display image in Image control?

    Using code to set Picture property was required before Access2007. Now the control has ControlSource property. Can simply be BOUND to an Attachment field or to a text field that has image path. Or an expression that builds the path.

    Have you step debugged? Where are you calling this function from?
    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.

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

Similar Threads

  1. Replies: 24
    Last Post: 06-26-2014, 11:23 AM
  2. Database Icon, Icons and Pictures problem
    By trevor40 in forum Access
    Replies: 8
    Last Post: 03-24-2014, 05:39 PM
  3. Inserting HTML Code
    By warrenk in forum Queries
    Replies: 1
    Last Post: 06-13-2013, 04:47 PM
  4. Replies: 3
    Last Post: 01-06-2012, 03:30 PM
  5. inserting bound pictures
    By inquisitive in forum Access
    Replies: 1
    Last Post: 01-09-2006, 09:59 AM

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