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