-----Original Message-----
Hi Patrick,
In general, I always try to avoid putting images in my
databases. Storing images in the database will make it
huge and slow very quickly.
Instead, I try to define a structured way of saving and
naming the images, and then set them as the source for an
Image Frame at run time. Or, if the name and path to an
image cannot be automatically constructed (based on the
record key or something of that nature), I store the path
and filename only in a regular text field, then use that
to set the image frame source at run time.
I have had the need to display OLE data from a SQL
database that I have read-only rights to. In that case,
I could not use a bound object frame because Access did
not know what kind of data the field contained, so I used
some code to write the OLE data to a file with the .jpg
extension and then set that as the source for an image
frame. But, in order to keep from slowing down the form
too much, I only do this when the user selects an option
group item to display the image. The SQL database that I
link to has 2 OLE fields, so the unbound option group has
three options: No Image, Vicinity Map, and Project
Schedule. The Form's current event sets the value of the
group to "No Image" by default when going to a new
record. The code to display the image is in the option
group's After Update event.
In case you are interested, the code that I use for this
process is listed below (It looks long, but it's mostly
comments). Watch the wrapping though.
Private Sub FrmUPRSImgOpt_AfterUpdate()
'This procedure saves the OLE data for a UPRS Map or
Gantt Chart to a .jpg file and displays the image
'in an image control on the form.
Dim varProjMap As Variant
Dim bArray() As Byte
Dim strImageFileName As String
Dim rst As DAO.Recordset, dbs As DAO.Database
'Check to see if the user selected "None", in which case
no image is displayed
If Me.FrmUPRSImgOpt = 0 Then
Me.ImgUPRS.Visible = False
Exit Sub
End If
'Check to see if the WCIP project is linked to a UPRS
Project
If IsNull(Me![UPRS ID Ref]) Then
'If there is no value in the UPRS ID Ref field, it is
not possible to display and image.
'Notify the User
MsgBox "There is no UPRS ID - Images can only be
displayed for projects with a UPRS ID"
'Hide the picture to avoid having it display a
previous image that may
'be for another project
Me.ImgUPRS.Visible = False
'Exit the Procedure
Exit Sub
End If
'set the dbs variable to represent the current database
Set dbs = CurrentDb
'set the rst variable to represent the
tzimpUPRSOLEObjects table
Set rst = dbs.OpenRecordset("tzimpUPRSOLEObjects",
dbOpenDynaset)
'Do all of the following with rst
With rst
'Find the index value matching the one for the
account selected by the user
'.Seek "=", Me![UPRS ID Ref]
.FindFirst ("[ProjectID] = " & Me![UPRS ID Ref])
'If no match is found
If .NoMatch = True Then
'Notify the user
MsgBox "Sorry, there are no images for this UPRS
Project ID"
'Hide the picture to avoid having it display a
previous image that may
'be for another project
Me.ImgUPRS.Visible = False
'Exit the Procedure
Exit Sub
End If
'check to see which image field to grab based on the
option group value
If Me.FrmUPRSImgOpt = 1 Then
'If the value is one it means the user has
selected the Map option
'Assign the varProjMap variable to contain the
contents of the Map field in the recordset
varProjMap = rst![Map]
'Assign the image file name
strImageFileName = "Map.jpg"
Else
'If the value is not one (it will be two) it
means the user has selected the Gantt option
'Assign the varProjMap variable to contain the
contents of the Gantt field in the recordset
varProjMap = rst![GanttChart]
'Assign the image file name
strImageFileName = "Gantt.jpg"
End If
'close the recordset now that we are done with it
.Close
End With
'unload the recordset object from memory
Set rst = Nothing
'Is the field empty for this record? If so, don't assign
a photo.
If IsNull(varProjMap) Then
'Hide the picture to avoid having it display a
previous image that may
'be for another project
Me.ImgUPRS.Visible = False
'Notify the user
MsgBox "Sorry, the requested Image has not been
entered in UPRS"
Exit Sub
End If
'Set the image properties to display the image
Me.ImgUPRS.Visible = True
'Resize array to hold BLOB
ReDim bArray(LenB(varProjMap) - 1)
'Copy varProjMap to byte array
bArray = varProjMap
'Insert Path before the File Name of .jpg file to be
created from the OLE Field
'by using the Project Folder function to return the path
to the project folder
strImageFileName = ProjectFolder(Me![ID]) &
strImageFileName
'Create a .jpg file to write the Binary data to
Open strImageFileName For Binary Access Write As #1
'Write binary data to the newly created .jpg file
Put #1, , bArray
'Close the new .jpg file
Close #1
'Bind the new .jpg file to the ImageFrame
Me.ImgUPRS.Picture = strImageFileName
End Sub
Not sure if any of this will help your situation, but I
thought that I would provide it in case it would.
-Ted Allen
-----Original Message-----
HI!!
I've been trying to copy a .jpg image to a OLE Object
type
in a table, and so far it works. I've been using the
example from this address:
http://support.microsoft.com/default.aspx?scid=kb;en-
us;210486&Product=acc
Today, I need the help of an expert because I'm trying
to
extract the image from my table.
For more details, see the 'WriteBlob' function at the
above link. It details how to get the image(from a
table)
and how to send-it to another file.
What I need: Can You help me figure out how to change
the
destination to an image box instead of another file...
I think that 'fileData' is the key, but not sure if this
info can be read by an image box.
The expected result is a 'View'(image box),on a form, of
the .jpg so the user can decide if this is the right
picture he or she wants.
Any help in atempting to solve this problem will be much
appriciated,
PAtrick
.
.