Here is some code to link images in reports. I've seen this asked several times on this board, so I hope this helps...
Private Sub Detail_Format(Cancel As Integer, FormatCount As Integer)
On Error Resume Next
Dim DBpath As String
DBpath = [Forms]![Main]![Img_Path]
If Dir$(DBpath & [ID] & "_1t.bmp") = [ID] & "_1t.bmp" Then
Me.ImageCover1.Picture = DBpath & [ID] & "_1t.bmp"
Else: Me.ImageCover1.Picture = DBpath & No_Image_m.bmp
End If
Me![VideoImage].Picture = DBpath & "stars-" & Me![VideoFile] & ".bmp"
Me![AudioImage].Picture = DBpath & "stars-" & Me![AudioFile] & ".bmp"
Me![ExtrasImage].Picture = DBpath & "stars-" & Me![ExtrasFile] & ".bmp"
Me![MovieImage].Picture = DBpath & "stars-" & Me![MovieFile] & ".bmp"
End Sub
This is what you'll get... http://img.photobucket.com/albums/v521/kecline/Access/rptMultImage.jpg
The code verifies that the image exists - if not, the no_image_m.bmp is displayed on the report.
The last 4 images are for the star ratings, which work in the same manner.
-Ken
aartjongejans
04-19-2006, 06:35 AM
Hi,
Your example looks great, I tried to implement your code but nothing happens? I have a database with employee date. Last name, first name etc. I want to make ID cards, so I made a report with the data I want on the card. Name, employee number etc. Also selected the table which contains a Photo. This Photo table contains the pathname. When I create the report, I have created a ImageFrame and implemented your vb code. I am not experienced in vb. Any suggestions?
Greatz,
Aart (Holland)
giovi2002
04-26-2006, 02:07 PM
For instance if you have employees make an employeeid footer and header. Place an imageframe in the footer and put a picture element inside it (for instance you refer to c:\temp\mypicture.bmp, the picture should exist).
- Name this image picture element imageframe
- Place an unbound text control within the footer named txtImageNote
Within the report in the footer event within the 'bijopmaken' (onformat) event
place the following code : Me!txtImageNote = DisplayImage(Me!ImageFrame, Me!FILENAME)
'Filename' is the name of the field within your query. Your field filename within the query should refer to pictures on disk (for instance c:\tem\mypic.bmp).
For instance the query looks like this
Select employeeid, filename
from
employees
Underneath the procedure which you'll be calling, place it in a module
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
In this way the report will show each picture per employee
of course you'll be able to use it in forms also
I have a report that is actually a letter generated to a specific individual identified by the database and to be signed with a signature on file as a bitmap image. I have created an image frame as you outlined previously in the report, but it is not in the footer - rather it is in the detail section. Let me know if it has to be in the footer. The signature will vary depending on who the document is written under and should link to C:\INVLOG\Signatures.ImageFile.bmp. I'm having a difficult time figuring out how to link this imageframe to the appropriate signature. I do have the ImageFile.bmp files named with the same number as the ID number for the person signing the letter.
aartjongejans
05-23-2006, 11:33 PM
Thanks,
Due to computer problems I was unable to go online for a while. Will go and test your code
Steve R.
12-01-2006, 02:43 PM
The following code allows you to manage your images. It is also dependent on code posted by Ukraine82 (http://www.access-programmers.co.uk/forums/showthread.php?t=85232) on April 20, 2005. You will need to download his code and store it as a module. Also please be aware that TEXT62 refers to a field that contains the relative path to the image file.
Public Sub Form_Current()
On Error GoTo Err_Form_Current
FileExistsbol = False
Me.Image70.Visible = True
Rem ---------------------------------------------------------------------------
Rem Check to see if Image Exists
Rem Modified from code Developed by Ukraine82 on the following Forum: http://www.access-programmers.co.uk/forums/index.php
Rem ---------------------------------------------------------------------------
FullDirectoryPath = CurrentProject.Path & Me.Text62
FileExistsbol = Dir(FullDirectoryPath) <> vbNullString
If FileExistsbol Then
Me.Image70.Picture = Trim(FullDirectoryPath)
Else
DoCmd.RunCommand acCmdSaveRecord
MSG = "Missing Image"
TTL = "MISSING IMAGE"
Me.Image70.Visible = False
MsgBox MSG, vbOKOnly, TTL
Call ADDIMAGE01FRM
End If
Rem ---------------------------------------------------------------------------
Rem END END Check to see if Image Exists
Rem ---------------------------------------------------------------------------
Me.SubForm01.Visible = False
Call Lock_Controls
Me.TEXT5 = "Novel"
Select Case CATEGORY
Case "A"
Me.SubForm01.Visible = True
Me.SubForm01.SourceObject = "anthologysubfrm"
Me.TEXT5 = "Anthology"
Case "C"
Me.SubForm01.Visible = True
Me.SubForm01.SourceObject = "compilationsubfrm"
Me!SubForm01.Form!STORYNAME.Width = TMPWIDTH
If Me!SubForm01.Form.Recordset.RecordCount > 15 Then
Me.SubForm01.Form.ScrollBars = 2
Me.SubForm01.Form!STORYNAME.Width = TMPWIDTH - SCROLLBARWIDTH
Else
Me!SubForm01.Form.ScrollBars = 0
End If
Me.TEXT5 = "Compilation"
End Select
Rem DoCmd.GoToControl "title"
Exit_Form_Current:
Exit Sub
Err_Form_Current:
MSG = "The link to the image is invalid. Please create a new link. " & Chr$(13) & Err.Description & "Error Number: " & Err.NUMBER
TTL = "BROKEN IMAGE LINK"
Select Case Err.NUMBER
Case 52 'bad file name
Rem Debug.Print "case52"
Me.Text62 = Null
Rem Me.IMAGELOCATION = Null
MsgBox MSG, vbOKOnly, TTL
FileExistsbol = False
Resume Exit_Form_Current
Case 2220 'Cannot access the file.
Rem Debug.Print "Case 2220"
Me.Text62 = Null
Rem Me.IMAGELOCATION = Null
MsgBox MSG, vbOKOnly, TTL
FileExistsbol = False
Resume Exit_Form_Current
Case Else
Rem Debug.Print "Error Routine Triggered: "; Err.NUMBER
TTL = "UNEXPECTED ERROR"
MsgBox Err.Description & " Error Number: " & Err.NUMBER, vbOKOnly, TTL
Resume Exit_Form_Current
End Select
End Sub