john123
04-17-2005, 07:24 AM
Hey guys,
I would like to use the following code in a project but I do not quite understand it, can someone help by quickly annotating it further thanks:
Option Compare Database
Option Explicit
Public Function DisplayImage(ctlImageControl As Control, strImagePath As Variant) As String
On Error GoTo Err_DisplayImage ' If any other error goto error message
Dim strResult As String
Dim strDatabasePath As String
Dim intSlashLocation As Integer
With ctlImageControl
If IsNull(strImagePath) Then 'if the loactaion of the is not there
.Visible = False 'no picture to view
strResult = "No image name specified." ' if there is no image path name then dispaly "result"
Else
If InStr(1, strImagePath, "\") = 0 Then 'if image path contains "\" then there is a valid path
strDatabasePath = CurrentProject.FullName
intSlashLocation = InStrRev(strDatabasePath, "\", Len(strDatabasePath))
strDatabasePath = Left(strDatabasePath, intSlashLocation)
strImagePath = strDatabasePath & strImagePath
End If
.Visible = True 'Picture found
.Picture = strImagePath ' view picture
strResult = "Image found and displayed." ' If path exists and is valid display "result"
End If
End With
Exit_DisplayImage:
DisplayImage = strResult ' Shows the result in txt box for testing purposes
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
I would like to use the following code in a project but I do not quite understand it, can someone help by quickly annotating it further thanks:
Option Compare Database
Option Explicit
Public Function DisplayImage(ctlImageControl As Control, strImagePath As Variant) As String
On Error GoTo Err_DisplayImage ' If any other error goto error message
Dim strResult As String
Dim strDatabasePath As String
Dim intSlashLocation As Integer
With ctlImageControl
If IsNull(strImagePath) Then 'if the loactaion of the is not there
.Visible = False 'no picture to view
strResult = "No image name specified." ' if there is no image path name then dispaly "result"
Else
If InStr(1, strImagePath, "\") = 0 Then 'if image path contains "\" then there is a valid path
strDatabasePath = CurrentProject.FullName
intSlashLocation = InStrRev(strDatabasePath, "\", Len(strDatabasePath))
strDatabasePath = Left(strDatabasePath, intSlashLocation)
strImagePath = strDatabasePath & strImagePath
End If
.Visible = True 'Picture found
.Picture = strImagePath ' view picture
strResult = "Image found and displayed." ' If path exists and is valid display "result"
End If
End With
Exit_DisplayImage:
DisplayImage = strResult ' Shows the result in txt box for testing purposes
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