ronculbert
New member
- Local time
- Today, 01:37
- Joined
- Aug 8, 2006
- Messages
- 8
I am tring to generate a report in Access and print it to Adobe PDF with multiple linked images. I am able to do this but I get caught in some sort of loop that realy bogs down my system and some times locks me up. I am tring to display 14 images. I modified a peice of code I got from MSDN that works fine on my form but not my report. Thank you for any help you can provide!
This is the Module I am using
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
This Is the Code behind my Report.
Function setImagePath()
Dim strImagePath As String
Dim imageOne As String
On Error GoTo PictureNotAvailable
imageOne = Me.txtImageName1
strImagePath = storedImagePath & imageOne
Me.ImageFrame.Picture = strImagePath
Exit Function
PictureNotAvailable:
strImagePath = noImage
Me.ImageFrame.Picture = strImagePath
End Function
Function setImagePath2()
Dim strImagePath2 As String
Dim imageTwo As String
On Error GoTo PictureNotAvailable
imageTwo = Me.txtImageName2
strImagePath2 = storedImagePath & imageTwo
Me.ImageFrame2.Picture = strImagePath2
Exit Function
PictureNotAvailable:
strImagePath2 = noImage
Me.ImageFrame2.Picture = strImagePath2
End Function
Function setImagePath3()
Dim strImagePath3 As String
Dim imageThree As String
On Error GoTo PictureNotAvailable
imageThree = Me.txtImageName3
strImagePath3 = storedImagePath & imageThree
Me.ImageFrame3.Picture = strImagePath3
Exit Function
PictureNotAvailable:
strImagePath3 = noImage
Me.ImageFrame3.Picture = strImagePath3
End Function
Function setImagePath4()
Dim strImagePath4 As String
Dim imageFour As String
On Error GoTo PictureNotAvailable
imageFour = Me.txtImageName4
strImagePath4 = storedImagePath & imageFour
Me.ImageFrame4.Picture = strImagePath4
Exit Function
PictureNotAvailable:
strImagePath4 = noImage
Me.ImageFrame4.Picture = strImagePath4
End Function
Function setImagePath5()
Dim strImagePath5 As String
Dim imageFive As String
On Error GoTo PictureNotAvailable
imageFive = Me.txtImageName5
strImagePath5 = storedImagePath & imageFive
Me.ImageFrame5.Picture = strImagePath5
Exit Function
PictureNotAvailable:
strImagePath5 = noImage
Me.ImageFrame5.Picture = strImagePath5
End Function
Function setImagePath6()
Dim strImagePath6 As String
Dim imageSix As String
On Error GoTo PictureNotAvailable
imageSix = Me.txtImageName6
strImagePath6 = storedImagePath & imageSix
Me.ImageFrame6.Picture = strImagePath6
Exit Function
PictureNotAvailable:
strImagePath6 = noImage
Me.ImageFrame6.Picture = strImagePath6
End Function
Function setImagePath7()
Dim strImagePath7 As String
Dim imageSeven As String
On Error GoTo PictureNotAvailable
imageSeven = Me.txtImageName7
strImagePath7 = storedImagePath & imageSeven
Me.ImageFrame7.Picture = strImagePath7
Exit Function
PictureNotAvailable:
strImagePath7 = noImage
Me.ImageFrame7.Picture = strImagePath7
End Function
Function setImagePath8()
Dim strImagePath8 As String
Dim imageEight As String
On Error GoTo PictureNotAvailable
imageEight = Me.txtImageName8
strImagePath8 = storedImagePath & imageEight
Me.ImageFrame8.Picture = strImagePath8
Exit Function
PictureNotAvailable:
strImagePath8 = noImage
Me.ImageFrame8.Picture = strImagePath8
End Function
Function setImagePath9()
Dim strImagePath9 As String
Dim imageNine As String
On Error GoTo PictureNotAvailable
imageNine = Me.txtImageName9
strImagePath9 = storedImagePath & imageNine
Me.ImageFrame9.Picture = strImagePath9
Exit Function
PictureNotAvailable:
strImagePath9 = noImage
Me.ImageFrame9.Picture = strImagePath9
End Function
Function setImagePath10()
Dim strImagePath10 As String
Dim imageTen As String
On Error GoTo PictureNotAvailable
imageTen = Me.txtImageName10
strImagePath10 = storedImagePath & imageTen
Me.ImageFrame10.Picture = strImagePath10
Exit Function
PictureNotAvailable:
strImagePath10 = noImage
Me.ImageFrame10.Picture = strImagePath10
End Function
Function setImagePath11()
Dim strImagePath11 As String
Dim imageEleven As String
On Error GoTo PictureNotAvailable
imageEleven = Me.txtImageName11
strImagePath11 = storedImagePath & imageEleven
Me.ImageFrame11.Picture = strImagePath11
Exit Function
PictureNotAvailable:
strImagePath11 = noImage
Me.ImageFrame11.Picture = strImagePath11
End Function
Function setImagePath12()
Dim strImagePath12 As String
Dim imageTwelve As String
On Error GoTo PictureNotAvailable
imageTwelve = Me.txtImageName12
strImagePath12 = storedImagePath & imageTwelve
Me.ImageFrame12.Picture = strImagePath12
Exit Function
PictureNotAvailable:
strImagePath12 = noImage
Me.ImageFrame12.Picture = strImagePath12
End Function
Function setImagePath13()
Dim strImagePath13 As String
Dim imageThirteen As String
On Error GoTo PictureNotAvailable
imageThirteen = Me.txtImageName13
strImagePath13 = storedImagePath & imageThirteen
Me.ImageFrame13.Picture = strImagePath13
Exit Function
PictureNotAvailable:
strImagePath13 = noImage
Me.ImageFrame13.Picture = strImagePath13
End Function
Function setImagePath14()
Dim strImagePath14 As String
Dim imageFourteen As String
On Error GoTo PictureNotAvailable
imageFourteen = Me.txtImageName14
strImagePath14 = storedImagePath & imageFourteen
Me.ImageFrame14.Picture = strImagePath14
Exit Function
PictureNotAvailable:
strImagePath14 = noImage
Me.ImageFrame14.Picture = strImagePath14
End Function
Private Sub Detail_Format(Cancel As Integer, FormatCount As Integer)
Dim ImageCheck As String
ImageCheck = setImagePath()
ImageCheck = setImagePath2()
ImageCheck = setImagePath3()
ImageCheck = setImagePath4()
ImageCheck = setImagePath5()
ImageCheck = setImagePath6()
ImageCheck = setImagePath7()
ImageCheck = setImagePath8()
ImageCheck = setImagePath9()
ImageCheck = setImagePath10()
ImageCheck = setImagePath11()
ImageCheck = setImagePath12()
ImageCheck = setImagePath13()
ImageCheck = setImagePath14()
End Sub
This is the Module I am using
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
This Is the Code behind my Report.
Function setImagePath()
Dim strImagePath As String
Dim imageOne As String
On Error GoTo PictureNotAvailable
imageOne = Me.txtImageName1
strImagePath = storedImagePath & imageOne
Me.ImageFrame.Picture = strImagePath
Exit Function
PictureNotAvailable:
strImagePath = noImage
Me.ImageFrame.Picture = strImagePath
End Function
Function setImagePath2()
Dim strImagePath2 As String
Dim imageTwo As String
On Error GoTo PictureNotAvailable
imageTwo = Me.txtImageName2
strImagePath2 = storedImagePath & imageTwo
Me.ImageFrame2.Picture = strImagePath2
Exit Function
PictureNotAvailable:
strImagePath2 = noImage
Me.ImageFrame2.Picture = strImagePath2
End Function
Function setImagePath3()
Dim strImagePath3 As String
Dim imageThree As String
On Error GoTo PictureNotAvailable
imageThree = Me.txtImageName3
strImagePath3 = storedImagePath & imageThree
Me.ImageFrame3.Picture = strImagePath3
Exit Function
PictureNotAvailable:
strImagePath3 = noImage
Me.ImageFrame3.Picture = strImagePath3
End Function
Function setImagePath4()
Dim strImagePath4 As String
Dim imageFour As String
On Error GoTo PictureNotAvailable
imageFour = Me.txtImageName4
strImagePath4 = storedImagePath & imageFour
Me.ImageFrame4.Picture = strImagePath4
Exit Function
PictureNotAvailable:
strImagePath4 = noImage
Me.ImageFrame4.Picture = strImagePath4
End Function
Function setImagePath5()
Dim strImagePath5 As String
Dim imageFive As String
On Error GoTo PictureNotAvailable
imageFive = Me.txtImageName5
strImagePath5 = storedImagePath & imageFive
Me.ImageFrame5.Picture = strImagePath5
Exit Function
PictureNotAvailable:
strImagePath5 = noImage
Me.ImageFrame5.Picture = strImagePath5
End Function
Function setImagePath6()
Dim strImagePath6 As String
Dim imageSix As String
On Error GoTo PictureNotAvailable
imageSix = Me.txtImageName6
strImagePath6 = storedImagePath & imageSix
Me.ImageFrame6.Picture = strImagePath6
Exit Function
PictureNotAvailable:
strImagePath6 = noImage
Me.ImageFrame6.Picture = strImagePath6
End Function
Function setImagePath7()
Dim strImagePath7 As String
Dim imageSeven As String
On Error GoTo PictureNotAvailable
imageSeven = Me.txtImageName7
strImagePath7 = storedImagePath & imageSeven
Me.ImageFrame7.Picture = strImagePath7
Exit Function
PictureNotAvailable:
strImagePath7 = noImage
Me.ImageFrame7.Picture = strImagePath7
End Function
Function setImagePath8()
Dim strImagePath8 As String
Dim imageEight As String
On Error GoTo PictureNotAvailable
imageEight = Me.txtImageName8
strImagePath8 = storedImagePath & imageEight
Me.ImageFrame8.Picture = strImagePath8
Exit Function
PictureNotAvailable:
strImagePath8 = noImage
Me.ImageFrame8.Picture = strImagePath8
End Function
Function setImagePath9()
Dim strImagePath9 As String
Dim imageNine As String
On Error GoTo PictureNotAvailable
imageNine = Me.txtImageName9
strImagePath9 = storedImagePath & imageNine
Me.ImageFrame9.Picture = strImagePath9
Exit Function
PictureNotAvailable:
strImagePath9 = noImage
Me.ImageFrame9.Picture = strImagePath9
End Function
Function setImagePath10()
Dim strImagePath10 As String
Dim imageTen As String
On Error GoTo PictureNotAvailable
imageTen = Me.txtImageName10
strImagePath10 = storedImagePath & imageTen
Me.ImageFrame10.Picture = strImagePath10
Exit Function
PictureNotAvailable:
strImagePath10 = noImage
Me.ImageFrame10.Picture = strImagePath10
End Function
Function setImagePath11()
Dim strImagePath11 As String
Dim imageEleven As String
On Error GoTo PictureNotAvailable
imageEleven = Me.txtImageName11
strImagePath11 = storedImagePath & imageEleven
Me.ImageFrame11.Picture = strImagePath11
Exit Function
PictureNotAvailable:
strImagePath11 = noImage
Me.ImageFrame11.Picture = strImagePath11
End Function
Function setImagePath12()
Dim strImagePath12 As String
Dim imageTwelve As String
On Error GoTo PictureNotAvailable
imageTwelve = Me.txtImageName12
strImagePath12 = storedImagePath & imageTwelve
Me.ImageFrame12.Picture = strImagePath12
Exit Function
PictureNotAvailable:
strImagePath12 = noImage
Me.ImageFrame12.Picture = strImagePath12
End Function
Function setImagePath13()
Dim strImagePath13 As String
Dim imageThirteen As String
On Error GoTo PictureNotAvailable
imageThirteen = Me.txtImageName13
strImagePath13 = storedImagePath & imageThirteen
Me.ImageFrame13.Picture = strImagePath13
Exit Function
PictureNotAvailable:
strImagePath13 = noImage
Me.ImageFrame13.Picture = strImagePath13
End Function
Function setImagePath14()
Dim strImagePath14 As String
Dim imageFourteen As String
On Error GoTo PictureNotAvailable
imageFourteen = Me.txtImageName14
strImagePath14 = storedImagePath & imageFourteen
Me.ImageFrame14.Picture = strImagePath14
Exit Function
PictureNotAvailable:
strImagePath14 = noImage
Me.ImageFrame14.Picture = strImagePath14
End Function
Private Sub Detail_Format(Cancel As Integer, FormatCount As Integer)
Dim ImageCheck As String
ImageCheck = setImagePath()
ImageCheck = setImagePath2()
ImageCheck = setImagePath3()
ImageCheck = setImagePath4()
ImageCheck = setImagePath5()
ImageCheck = setImagePath6()
ImageCheck = setImagePath7()
ImageCheck = setImagePath8()
ImageCheck = setImagePath9()
ImageCheck = setImagePath10()
ImageCheck = setImagePath11()
ImageCheck = setImagePath12()
ImageCheck = setImagePath13()
ImageCheck = setImagePath14()
End Sub