How do I Load UNBOUND Image Control with DIB stored in table

  • Thread starter George Nicholson
  • Start date
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
*************************************
 
G

Graham Mandeno

Hi George

If you are using the same logo on many different forms and reports, why not
create a subform with the logo in a bound control, and use that subform
repeatedly in the other places?

Also, I don't understand the objection to an external image file. If the
user is able to change the image, then surely it is much easier to use an
Open File dialog and store a new image file name in a table?
 

Ask a Question

Want to reply to this thread or ask your own question?

You'll need to choose a username for the site, which only take a couple of moments. After that, you can post your question and our members will help you out.

Ask a Question

Top