'
' Module Nam: PictureFromFile
' Devloped by: Maj P
' Purpose: This classs creates funtionality so that a form with an image box
'and a control with a path name, will automatically show the image whose path is contained
'in the control. The form must be in single form view, the report must force a page break after the
'detail section so that there is one record per page. This does not work in a continous
'view.
'
' To Use: Drop the below code into a CLASS module and name the
' Class module "PictureFromFile". Then in a
' form/report do the following:
'
' FORM / REPORT CODE
'
'*********************************************************************
' Public objPictureFromFile As PictureFromFile
' Private Sub Form_Open(Cancel As Integer)
' Set objPictureFromFile = New PictureFromFile
' (for a form) Set objPictureFromFile.PictureForm = Me
' (for a Report) Set objPictureFromFile.PictureReport = Me
' Set objPictureFromFile.PictureControl = Me.imgCntrlOne
' Set objPictureFromFile.PictureNameControl = Me.txtBxPicPath
' End Sub
'**********************************************************************
'END FORM/REPORT CODE
'
'
'
'CLASS CODE
Option Compare Database
Option Explicit
Private mPictureNameControl As TextBox
Private mImagePath As String
Private mImageControl As Image
Private WithEvents mForm As Access.Form
Private WithEvents mReport As Access.Report
Public Property Set PictureNameControl(thePictureNameControl As TextBox)
Set mPictureNameControl = thePictureNameControl
End Property
Public Property Set PictureControl(theControl As Image)
Set mImageControl = theControl
End Property
Public Property Set PictureForm(theForm As Access.Form)
On Error GoTo HandleError
Set mForm = theForm
mForm.OnCurrent = "[Event Procedure]"
Exit Property
HandleError:
MsgBox Err.Number & " " & Err.Description
End Property
Public Property Set PictureReport(theReport As Access.Report)
Set mReport = theReport
mReport.OnPage = "[Event Procedure]"
mReport.OnActivate = "[Event Procedure]"
End Property
Private Sub subLoadImage()
Dim strImagePathAndFile As String
Dim objFileSystem As Object
Dim connection As String
Set objFileSystem = CreateObject("Scripting.FileSystemObject")
On Error GoTo PictureNotAvailable
strImagePathAndFile = Nz(mPictureNameControl.Value, "")
mImageControl.Visible = True
If objFileSystem.FileExists(strImagePathAndFile) Then
mImageControl.Picture = strImagePathAndFile
mImageControl.Visible = True
mImagePath = strImagePathAndFile
Else
mImageControl.Picture = ""
mImageControl.Visible = False
End If
Exit Sub
PictureNotAvailable:
MsgBox Err.Number & " " & Err.Description & Chr(13) & "In PictureFromFile Class"
End Sub
Private Sub mForm_Current()
Call subLoadImage
End Sub
Private Sub mReport_Activate()
Call subLoadImage
End Sub
Private Sub mReport_Page()
Call subLoadImage
End Sub
Public Property Get ImagePath() As String
ImagePath = mImagePath
End Property