[COLOR="DarkGreen"]'Declare Variables...[/COLOR]
Dim MyPicFile As String
Dim rpt As New Report
Dim RptName As String
[COLOR="DarkGreen"]'Fill the MyPicFile string variable with the name
'of the image to print. Here we are simply using
'the DLookUp Function to acquire the Path and Image
'file name from Table. You can fill this variable
'any way you like.[/COLOR]
MyPicFile = Nz(DLookup("[PicPath]", "[MyTable]", "[PicID]=" & Whatever), "")
[COLOR="DarkGreen"]'Exit if it's found that the MyPicFile variable
'contains nothing (empty string).[/COLOR]
If MyPicFile = "" Then Exit Sub
[COLOR="DarkGreen"]'Trap Errors...[/COLOR]
On Error GoTo Error_PrintPic
[COLOR="DarkGreen"] 'Create the Temporary Report[/COLOR]
Set rpt = CreateReport()
[COLOR="DarkGreen"] 'Set Report Properties...[/COLOR]
With rpt
'.Visible = False
.PictureType = 1 [COLOR="DarkGreen"]'Linked[/COLOR]
.PictureSizeMode = 3 [COLOR="DarkGreen"]'Zoom[/COLOR]
.Picture = MyPicFile [COLOR="DarkGreen"]'The Picture (image) to Print[/COLOR]
RptName = .Name
End With
[COLOR="DarkGreen"]'Print the report...[/COLOR]
DoCmd.OpenReport RptName, , , , acHidden
Exit_PrintPic:
On Error Resume Next
[COLOR="DarkGreen"] 'Close the report[/COLOR]
DoCmd.Close acReport, RptName, acSaveNo
[COLOR="DarkGreen"] 'Delete the report[/COLOR]
DoCmd.DeleteObject acReport, RptName
Set rpt = Nothing
If Err <> 0 Then Err.Clear
Exit Sub
Error_PrintPic:
Dim ErrMsg As String
[COLOR="DarkGreen"]'Message selectable Errors...[/COLOR]
Select Case Err.Number
Case 2202
ErrMsg = "There is no Printer attached to system." & vbCr & _
"Please attach Printer and try again."
Case Else
ErrMsg = Err.Number & " -- " & Err.Description
End Select
MsgBox ErrMsg, vbExclamation, "Picture Print Error"
Resume Exit_PrintPic