Results 1 to 2 of 2
  1. #1
    jacopo186 is offline Novice
    Windows XP Access 2003
    Join Date
    Feb 2010
    Posts
    1

    Images with VBA code - COINS DB

    Hi all. I'm trying to build a database for a coins collector. I need to put 2 photos of the 2 sides for each coin (record). I used the code behind, but it allows me to see only 1 photo. Why? Where is the mistake in the 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
    Public Function DisplayImage2(ctlImageControl2 As Control, strImagePath2 As Variant) As String
    On Error GoTo Err_DisplayImage2
    Dim strResult2 As String
    Dim strDatabasePath2 As String
    Dim intSlashLocation2 As Integer
    With ctlImageControl2
    If IsNull(strImagePath2) Then
    .Visible = False
    strResult2 = "Indicare percorso e nome immagine"
    Else
    If InStr(1, strImagePath2, "\") = 0 Then
    ' Path is relative
    strDatabasePath2 = CurrentProject.FullName
    intSlashLocation2 = InStrRev(strDatabasePath2, "\", Len(strDatabasePath2))
    strDatabasePath2 = Left(strDatabasePath2, intSlashLocation2)
    strImagePath2 = strDatabasePath2 & strImagePath2
    End If
    .Visible = True
    .Picture = strImagePath2
    strResult2 = "Immagine correttamente individuata e visualizzata"
    End If
    End With
    Exit_DisplayImage2:
    DisplayImage2 = strResult2
    Exit Function
    Err_DisplayImage2:
    Select Case Err.Number
    Case 2220 ' Can't find the picture.
    ctlImageControl2.Visible = False
    strResult2 = "Immagine non trovata all'indirizzo specificato"
    Resume Exit_DisplayImage2:
    Case Else ' Some other error.
    MsgBox Err.Number & " " & Err.Description
    strResult2 = "Errore non specificato nella visualizzazione dell'immagine"
    Resume Exit_DisplayImage2:
    End Select
    End Function

  2. #2
    RuralGuy's Avatar
    RuralGuy is offline Administrator
    Windows 7 Access 2007
    Join Date
    Mar 2007
    Location
    8300' in the Colorado Rocky Mountains
    Posts
    12,922
    Have you put in a break and single stepped the code to see what is happening?

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

Similar Threads

  1. Replies: 17
    Last Post: 08-26-2009, 11:27 AM
  2. Newb- Trying to use images and such.
    By TriAdX in forum Access
    Replies: 3
    Last Post: 08-18-2009, 10:07 AM
  3. Images in report
    By rudyp in forum Reports
    Replies: 1
    Last Post: 03-24-2009, 09:51 PM
  4. Placing images quickly
    By marcello.dolcini in forum Import/Export Data
    Replies: 1
    Last Post: 10-20-2008, 06:05 AM

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