matt beamish
Registered User.
- Local time
- Today, 16:18
- Joined
- Sep 21, 2000
- Messages
- 215
I have used the code from
http://support.microsoft.com/default.aspx?scid=kb;en-us;285820
"How to display images from a folder in a form, a report, or a data access page"
to display images (of archaeological skeletons etc) in a database.
This has mostly worked well, and I am pleased. However, some of the images are too high a resolution to be displayed. I either have to batch resize the images to a lower res, or find a way of resizing the image as a function of it being displayed in the database. Has anyone done anything similar?
I also find that despite the indications that relative paths would be picked up automatically, they are not. My images need to be in the same folder location as the database for the link to work.
I am very green with code!
Thanks in advance.
Matt
http://support.microsoft.com/default.aspx?scid=kb;en-us;285820
"How to display images from a folder in a form, a report, or a data access page"
to display images (of archaeological skeletons etc) in a database.
Code:
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 has mostly worked well, and I am pleased. However, some of the images are too high a resolution to be displayed. I either have to batch resize the images to a lower res, or find a way of resizing the image as a function of it being displayed in the database. Has anyone done anything similar?
I also find that despite the indications that relative paths would be picked up automatically, they are not. My images need to be in the same folder location as the database for the link to work.
I am very green with code!
Thanks in advance.
Matt