Help needed:
I have a report in Access 2010. The report contains some images in the main report area and in sub reports. I have The queries that feed the report and subreport contains the name of the pictures that are loaded into its image controls. I added the following code to my form in order to control what image is displayed for each record. Id like the form to work even if the database is moved as long as the subfolder and photos are moved along with it (thus using relative path).
Code:
Private Sub Report_(Current)
Dim ImagePath As String
Dim ImagePathInt As String
Dim ImagePathPlanV As String
ImagePath = GetImagePath & Me!BackPhName
ImagePathInt = GetImagePath & Me!IntPhName
ImagePathPlanV = GetImagePath & Me!PlanVSketch
If Len([BackPhName]) > 0 And Len(Dir(ImagePath)) > 0 Then
ImgBackground.Picture = ImagePath
Else
ImgBackground.Picture = ""
End If
If Len([IntPhName]) > 0 And Len(Dir(ImagePathInt)) > 0 Then
ImgInternal.Picture = ImagePathInt
Else
ImgInternal.Picture = ""
End If
If Len([PlanVSketch]) > 0 And Len(Dir(ImagePathPlanV)) > 0 Then
ImgInternal.Picture = ImagePathPlanV
Else
ImgInternal.Picture = ""
End If
End Sub
Public Function GetImagePath() As String
GetImagePath = GetDBPath & "Renamed Photos Videos and Sketches\"
End Function
Public Function GetDBPath() As String
GetDBPath = CurrentProject.Path & "\"
End Function
The problem seems to be that the routine doesn't seem to initially recognize the path. I have a blank photo in the folder containing all the images called NO PHOTO.jpg. If I open the report in design view and browse to this image in the picture parameter of any one of the image controls and run the report, then everything works perfectly even if I close and reopen the report. The report shows the right pictures even in the subreports. The problem is when I close the database and reopen it, then the link is lost again, forcing me to do the process of browsing for the NO PHOTO image again.
I already try to do an open form procedure to automatically reset the picture property, but although it resets the picture to the picture I set (I verify this by setting a different picture instead of the NO PHOTO) it does not make things work correctly as it does when I manually browse for it in design view.
I also try to run the code above under the Report (Open) instead of the Report (Current) but that didn't work either. Any help figuring this out is greatly appreciated.
Thanks.