Embedding images into a table

Embedding images into a table

am 28.11.2007 10:23:51 von anthony

I want to embed some BMP files into an OLE field (called BMP) in an
existing table using code. I've created the code that grabs the
filename from the image folder, finds the corresponding record in the
table and opens that record for editing (RST.Edit). However, I'm
having difficulty putting the image into the OLE field. If I borrow
from the code that appears in http://support.microsoft.com/default.aspx/kb/158941,
then at RST!BMP.Class = "Paint.Picture" I get the error "Method or
data member not found"; ditto with OLETypeAllowed, SorceDoc and
Action. If I just try RST!BMP = strFileName, followed by RST.Update,
then the field displays "Long Binary Data" but whatever is in it is
not an image. Clearly, I need to prepare the OLE field somehow but it
seems to be different doing it directly to the table than via a form
as per Microsoft's example.

Could someone please help me with the syntax? Many thanks

Re: Embedding images into a table

am 28.11.2007 16:55:23 von Stephen Lebans

Post the code you are using.

--

HTH
Stephen Lebans
http://www.lebans.com
Access Code, Tips and Tricks
Please respond only to the newsgroups so everyone can benefit.


"anthony" wrote in message
news:dd164548-f571-442a-8b92-2e102538c858@v4g2000hsf.googleg roups.com...
>I want to embed some BMP files into an OLE field (called BMP) in an
> existing table using code. I've created the code that grabs the
> filename from the image folder, finds the corresponding record in the
> table and opens that record for editing (RST.Edit). However, I'm
> having difficulty putting the image into the OLE field. If I borrow
> from the code that appears in
> http://support.microsoft.com/default.aspx/kb/158941,
> then at RST!BMP.Class = "Paint.Picture" I get the error "Method or
> data member not found"; ditto with OLETypeAllowed, SorceDoc and
> Action. If I just try RST!BMP = strFileName, followed by RST.Update,
> then the field displays "Long Binary Data" but whatever is in it is
> not an image. Clearly, I need to prepare the OLE field somehow but it
> seems to be different doing it directly to the table than via a form
> as per Microsoft's example.
>
> Could someone please help me with the syntax? Many thanks

Re: Embedding images into a table

am 29.11.2007 10:12:25 von anthony

Apologies for the delay - here is the code

Dim strBMPDir As String
Dim strFileName As String
Dim DB As Database
Dim RST As Recordset
Dim strSQL As String

On Error GoTo errH
Set DB = CurrentDb()

strBMPDir = "i:\photos\bmp"
strFileName = Dir(strBMPDir & "\" & "*.bmp", vbNormal)
strFileName = Left(strFileName, 14)
Do While Len(strFileName) = 14
strSQL = "SELECT tblPhoto.PhotoID, tblPhoto.Image, tblPhoto.BMP"
strSQL = strSQL & " FROM tblPhoto"
strSQL = strSQL & " WHERE (((tblPhoto.Image)=" & "'" & strFileName &
"'" & "));"
Set RST = DB.OpenRecordset(strSQL)
With RST
..Edit
!BMP.Class = "Paint.Picture" 'This is where it fails with "Method or
data member not found"; ditto for the next three lines
!BMP.OLETypeAllowed = acOLEEmbedded
!BMP.SourceDoc = strBMPDir & "\" & strFileName & ".bmp"
!BMP.Action = acOLECreateEmbed
..update
strFileName = Dir
strFileName = Left(strFileName, 14)
Loop

X:
Exit Sub

errH:

MsgBox Err.Description
Resume X

Re: Embedding images into a table

am 29.11.2007 10:54:40 von Jebusville

"anthony" wrote in message
news:654c72a2-d777-406f-9afc-36450b52efe9@f3g2000hsg.googleg roups.com...
> Apologies for the delay - here is the code
>
> With RST
> .Edit
> !BMP.Class = "Paint.Picture" 'This is where it fails with "Method or
> data member not found"; ditto for the next three lines
> !BMP.OLETypeAllowed = acOLEEmbedded
> !BMP.SourceDoc = strBMPDir & "\" & strFileName & ".bmp"
> !BMP.Action = acOLECreateEmbed

I'm ready to be shot down in flames here but AIUI !Fieldname is expecting a
value for that field, I don't think there are any arguments. Does the code
compile? Do you have Option Explicit declared in the module?

Keith.
www.keithwilby.com

Re: Embedding images into a table

am 29.11.2007 11:06:54 von Jebusville

"anthony" wrote in message
news:654c72a2-d777-406f-9afc-36450b52efe9@f3g2000hsg.googleg roups.com...

I've just read the code in the link and the names in the square brackets []
are referring to field names that the form is bound to, there's no recordset
(rs) being opened anywhere. Modifying your code to refer to the bound
fields ought to do it. Worth a try :-)

Regards,
Keith.
www.keithwilby.com

Re: Embedding images into a table

am 29.11.2007 12:22:02 von anthony

The form is unbound. What I am trying to achieve is to embed images
directly into the OLE field in the table via code on a command button
but I'm getting the syntax wrong when attempting to prepare the OLE
field to accept the bitmap

Re: Embedding images into a table

am 29.11.2007 12:45:22 von Jebusville

"anthony" wrote in message
news:e69a5784-5b5c-4c2e-940c-e8902a720e8d@a39g2000pre.google groups.com...
> The form is unbound. What I am trying to achieve is to embed images
> directly into the OLE field in the table via code on a command button
> but I'm getting the syntax wrong when attempting to prepare the OLE
> field to accept the bitmap
>

But the example uses a bound form and that's why your code is failing.
Can't you use a bound form and just replicate the example you sited in your
OP?

Re: Embedding images into a table

am 29.11.2007 14:12:56 von anthony

> Can't you use a bound form and just replicate the example you sited in your
> OP?

I could and I have and it all works. But I'd still like to know how
that MS code should be adapted so that the code I posted will work. It
must be possible to embed directly into a table without going via a
Bound Object Frame on a form

Re: Embedding images into a table

am 29.11.2007 14:56:41 von Jebusville

"anthony" wrote in message
news:7c633084-d93e-425b-858b-01875fec4982@o6g2000hsd.googleg roups.com...
>> Can't you use a bound form and just replicate the example you sited in
>> your
>> OP?
>
> I could and I have and it all works. But I'd still like to know how
> that MS code should be adapted so that the code I posted will work. It
> must be possible to embed directly into a table without going via a
> Bound Object Frame on a form

Dunno, but this compiles:

rs.Fields("FieldName").Properties("Class") = "whatever"

Take it at face value, it might point you in the right direction but then
again ...

Keith.

Re: Embedding images into a table

am 29.11.2007 16:25:52 von anthony

>> rs.Fields("FieldName").Properties("Class") = "whatever"

You are a devious fellow! I'll try it. Many thanks

Re: Embedding images into a table

am 29.11.2007 16:41:15 von Jebusville

"anthony" wrote in message
news:8821ddac-64c8-44d2-80c3-a278cbde1dea@i12g2000prf.google groups.com...
>>> rs.Fields("FieldName").Properties("Class") = "whatever"
>
> You are a devious fellow! I'll try it. Many thanks

You're welcome, hope you get it working.

Keith.

Re: Embedding images into a table

am 29.11.2007 18:30:18 von anthony

>> rs.Fields("FieldName").Properties("Class") = "whatever"

Gives me "Property not found" :-(

Syntax I'm using is:

With RST
..Edit
..Fields("BMP").Properties("Class") = "Paint.Picture"

Re: Embedding images into a table

am 29.11.2007 19:53:56 von Tony Toews

anthony wrote:

>I want to embed some BMP files into an OLE field (called BMP) in an
>existing table using code.

Stephen has some code for this kind of stuff at www.lebans.com. Not sure if it's of
any use but you can take a look.

Tony
--
Tony Toews, Microsoft Access MVP
Please respond only in the newsgroups so that others can
read the entire thread of messages.
Microsoft Access Links, Hints, Tips & Accounting Systems at
http://www.granite.ab.ca/accsmstr.htm
Tony's Microsoft Access Blog - http://msmvps.com/blogs/access/

Re: Embedding images into a table

am 29.11.2007 20:03:23 von anthony

Thanks so much. I'll have a look

Re: Embedding images into a table

am 30.11.2007 03:06:31 von Stephen Lebans

I don't think you can use DAO via VBA to embedd a COM object. Access hosts
COM via its OLE Frame controls.

OTTOMH there are a couple of ways around it. Please realize that I am
speaking out of my ass as I have always meant to, but never found the time,
to create a working solution.

1) If the Bitmaps are all the same size then you can create one record,
embedding the first Bitmap via an OLE Frame control. You then copy this
field value directly into a new record. Now simply replace the existing
copied Bitmap(it's a DIB) within the new record with the desired Bitmap
data. I have not tested to verify whether you have to compute a new CHecksum
or not.

2) The ExtractInventoryOLE solution on my site details the structure of the
Access OLE object Wrapper. It also details the structure of the embedded OLE
object for most popular formats, including the BMP produced from MS Paint.
The only thing missing is the code to produce the Checksum value that Access
creates/applies to the entire embedded object. I found a couple of old posts
via GoogleGRoups on this subject. I've got them saved somewhere on this
machine but you can find them easily Online.

--

HTH
Stephen Lebans
http://www.lebans.com
Access Code, Tips and Tricks
Please respond only to the newsgroups so everyone can benefit.


"Tony Toews [MVP]" wrote in message
news:8m2uk3d56kgeijae1ru1a00ukq49jsnq0e@4ax.com...
> anthony wrote:
>
>>I want to embed some BMP files into an OLE field (called BMP) in an
>>existing table using code.
>
> Stephen has some code for this kind of stuff at www.lebans.com. Not sure
> if it's of
> any use but you can take a look.
>
> Tony
> --
> Tony Toews, Microsoft Access MVP
> Please respond only in the newsgroups so that others can
> read the entire thread of messages.
> Microsoft Access Links, Hints, Tips & Accounting Systems at
> http://www.granite.ab.ca/accsmstr.htm
> Tony's Microsoft Access Blog - http://msmvps.com/blogs/access/

Re: Embedding images into a table

am 30.11.2007 08:58:57 von anthony

Thank you so much Stephen. I appreciate your advice

Re: Embedding images into a table

am 30.11.2007 09:47:00 von Jebusville

"anthony" wrote in message
news:e963bdd1-a2a0-4646-918b-7bc46c9a54fd@s12g2000prg.google groups.com...
>>> rs.Fields("FieldName").Properties("Class") = "whatever"
>
> Gives me "Property not found" :-(
>
> Syntax I'm using is:
>
> With RST
> .Edit
> .Fields("BMP").Properties("Class") = "Paint.Picture"

Does this help?:

http://www.thescripts.com/forum/thread207566.html

Specifically:

"OK, I have now resolved the latest problem. I had "Paint.Picture" as the
value for Class property, but the Windows File Association set up for BMP
files was Microsoft Office Picture Manager. Originally it had been Paint.
I changed the association back to Paint and it now works correctly, as it
did a few months ago. There is probably a Class value for Picture Manager,
but at present I don't know what it is."

Re: Embedding images into a table

am 30.11.2007 15:23:56 von anthony

Yes, I saw that a few days ago. In fact, my file association is
correct. I think we have to accept what Stephen Lebans has said in his
post and until I have time to try out some of his suggestions I'm
doing it all via a form