G
George Nicholson
How do I load a picture into an *unbound* Image Control when I only have the
object itself (stored in a table field) and no filepath/filename?
I'm storing a few logos in a table within my mdb. I'm playing with the idea
of loading them into my forms & reports at Runtime for various reasons (#1
being that the client tends to want to change them frequently, so I want to
set this up to be able to swap out logos easily). For just a few logos (that
each appear dozens of times), I don't want to use external files.
The code I'm using is something close to that below.
My stumbling block is the line:
ctlImageControl.Picture = rs!ImageObj '<<** Problem Line
have also tried
ctlImageControl.PictureData = rs!ImageObj
and have tried "Set" with each. None work, although the error messages vary
from "value too long" to "Object doesn't support" to "Not a dib" (and I have
specifically stored all the images as Dibs).
Any ideas?
TIA,
George
***************************
Public Function DisplayImageFromDB(ctlImageControl As Control, strStatus As
String) As String
On Error GoTo ErrHandler
' adapted from MSKB 285820 (as of May 2008)
Dim strResult As String
Dim db As DAO.Database
Dim rs As DAO.Recordset
With ctlImageControl
Set db = CurrentDb
Set rs = db.OpenRecordset("tbl_Images", dbOpenSnapshot)
rs.FindFirst "[CurrentStatus]='" & strStatus & "'"
If rs.NoMatch Then
strResult = "Image not found."
Else
.Visible = True
ctlImageControl.Picture = rs!ImageObj '<<** Problem Line
strResult = "Image found and displayed."
End If
End With
ExitHere:
Set rs = Nothing
Set db = Nothing
DisplayImageFromDB = strResult
Exit Function
ErrHandler:
Select Case err.Number
Case 2220 ' Can't find the picture.
ctlImageControl.Visible = False
strResult = "Can't find image in the specified name."
Resume ExitHere
Case Else ' Some other error.
MsgBox err.Number & " " & err.Description
strResult = "An error occurred displaying image."
Resume ExitHere
Resume
End Select
End Function
*************************************
object itself (stored in a table field) and no filepath/filename?
I'm storing a few logos in a table within my mdb. I'm playing with the idea
of loading them into my forms & reports at Runtime for various reasons (#1
being that the client tends to want to change them frequently, so I want to
set this up to be able to swap out logos easily). For just a few logos (that
each appear dozens of times), I don't want to use external files.
The code I'm using is something close to that below.
My stumbling block is the line:
ctlImageControl.Picture = rs!ImageObj '<<** Problem Line
have also tried
ctlImageControl.PictureData = rs!ImageObj
and have tried "Set" with each. None work, although the error messages vary
from "value too long" to "Object doesn't support" to "Not a dib" (and I have
specifically stored all the images as Dibs).
Any ideas?
TIA,
George
***************************
Public Function DisplayImageFromDB(ctlImageControl As Control, strStatus As
String) As String
On Error GoTo ErrHandler
' adapted from MSKB 285820 (as of May 2008)
Dim strResult As String
Dim db As DAO.Database
Dim rs As DAO.Recordset
With ctlImageControl
Set db = CurrentDb
Set rs = db.OpenRecordset("tbl_Images", dbOpenSnapshot)
rs.FindFirst "[CurrentStatus]='" & strStatus & "'"
If rs.NoMatch Then
strResult = "Image not found."
Else
.Visible = True
ctlImageControl.Picture = rs!ImageObj '<<** Problem Line
strResult = "Image found and displayed."
End If
End With
ExitHere:
Set rs = Nothing
Set db = Nothing
DisplayImageFromDB = strResult
Exit Function
ErrHandler:
Select Case err.Number
Case 2220 ' Can't find the picture.
ctlImageControl.Visible = False
strResult = "Can't find image in the specified name."
Resume ExitHere
Case Else ' Some other error.
MsgBox err.Number & " " & err.Description
strResult = "An error occurred displaying image."
Resume ExitHere
Resume
End Select
End Function
*************************************