By using this site, you agree to our updated Privacy Policy and our Terms of Use. Manage your Cookies Settings.
429,480 Members | 763 Online
Bytes IT Community
+ Ask a Question
Need help? Post your question and get tips & solutions from a community of 429,480 IT Pros & Developers. It's quick & easy.

Trouble copying a picture object from one table to another

P: n/a
Lyn
I am trying to copy selected fields from one table to another, by reading
the source table record into a recordset (ADO) and then copying the relevant
fields to an SQL statement "INSERT INTO...". The numeric and text fields
copy without a problem, but it all falls in a heap when I try to copy a
picture object field (data type OLE Object in both tables). I seem to be
missing something ???

Reduced to its simplest form, this is the code in question:

Dim Conn As ADODB.Connection
Dim RS As New ADODB.Recordset
Dim strSQL As String

strSQL = "SELECT Photo FROM tblPhotographs WHERE tblPhotographs.ID = " &
Me!PictureID
Set Conn = CurrentProject.Connection
RS.Open strSQL, Conn, adOpenStatic
If RS.RecordCount <> 1 Then
MsgBox "Picture Missing from tblPhotographs. "
RS.Close
GoTo ProcEnd
End If

strSQL = "INSERT INTO tblTmpGallery (Picture1) " & _
"VALUES ( " & RSP.Photo & ");"
DoCmd.RunSQL strSQL
RS.Close

This code gives me Error 2498 "An expression you entered is the wrong data
type for one of the arguments."

Both the source table field (Photo) and the destination field (Picture1) are
defined as OLE Object type.

I note that the "VALUES (xxx)" clause requires single quotes around text
data (ie, 'xxx'), but nothing around numeric data. Is there a special way
to present an OLE Object type in this clause (equivalent of "set" for an
object perhaps)? What am I doing wrong here?

TIA.

--
Cheers,
Lyn.
Nov 13 '05 #1
Share this Question
Share on Google+
5 Replies


P: n/a
On Thu, 16 Jun 2005 23:38:36 +1000, "Lyn" <lh******@iiNet.net.au>
wrote:

It has been stated here many times: storing images in the database
rather than in the file system and storing a path to them in the
database will cause many problems.

-Tom.

I am trying to copy selected fields from one table to another, by reading
the source table record into a recordset (ADO) and then copying the relevant
fields to an SQL statement "INSERT INTO...". The numeric and text fields
copy without a problem, but it all falls in a heap when I try to copy a
picture object field (data type OLE Object in both tables). I seem to be
missing something ???

Reduced to its simplest form, this is the code in question:

Dim Conn As ADODB.Connection
Dim RS As New ADODB.Recordset
Dim strSQL As String

strSQL = "SELECT Photo FROM tblPhotographs WHERE tblPhotographs.ID = " &
Me!PictureID
Set Conn = CurrentProject.Connection
RS.Open strSQL, Conn, adOpenStatic
If RS.RecordCount <> 1 Then
MsgBox "Picture Missing from tblPhotographs. "
RS.Close
GoTo ProcEnd
End If

strSQL = "INSERT INTO tblTmpGallery (Picture1) " & _
"VALUES ( " & RSP.Photo & ");"
DoCmd.RunSQL strSQL
RS.Close

This code gives me Error 2498 "An expression you entered is the wrong data
type for one of the arguments."

Both the source table field (Photo) and the destination field (Picture1) are
defined as OLE Object type.

I note that the "VALUES (xxx)" clause requires single quotes around text
data (ie, 'xxx'), but nothing around numeric data. Is there a special way
to present an OLE Object type in this clause (equivalent of "set" for an
object perhaps)? What am I doing wrong here?

TIA.


Nov 13 '05 #2

P: n/a
Lyn
Tom, thanks for your comments.

Are you saying that what I am trying to do can't be done? (As opposed to
being not good practice?)

--
Cheers,
Lyn.

"Tom van Stiphout" <no*************@cox.net> wrote in message
news:rj********************************@4ax.com...
On Thu, 16 Jun 2005 23:38:36 +1000, "Lyn" <lh******@iiNet.net.au>
wrote:

It has been stated here many times: storing images in the database
rather than in the file system and storing a path to them in the
database will cause many problems.

-Tom.

I am trying to copy selected fields from one table to another, by reading
the source table record into a recordset (ADO) and then copying the
relevant
fields to an SQL statement "INSERT INTO...". The numeric and text fields
copy without a problem, but it all falls in a heap when I try to copy a
picture object field (data type OLE Object in both tables). I seem to be
missing something ???

Reduced to its simplest form, this is the code in question:

Dim Conn As ADODB.Connection
Dim RS As New ADODB.Recordset
Dim strSQL As String

strSQL = "SELECT Photo FROM tblPhotographs WHERE tblPhotographs.ID = "
&
Me!PictureID
Set Conn = CurrentProject.Connection
RS.Open strSQL, Conn, adOpenStatic
If RS.RecordCount <> 1 Then
MsgBox "Picture Missing from tblPhotographs. "
RS.Close
GoTo ProcEnd
End If

strSQL = "INSERT INTO tblTmpGallery (Picture1) " & _
"VALUES ( " & RSP.Photo & ");"
DoCmd.RunSQL strSQL
RS.Close

This code gives me Error 2498 "An expression you entered is the wrong data
type for one of the arguments."

Both the source table field (Photo) and the destination field (Picture1)
are
defined as OLE Object type.

I note that the "VALUES (xxx)" clause requires single quotes around text
data (ie, 'xxx'), but nothing around numeric data. Is there a special way
to present an OLE Object type in this clause (equivalent of "set" for an
object perhaps)? What am I doing wrong here?

TIA.

Nov 13 '05 #3

P: n/a
No, it can be done. It's just not a good idea. If you store the
images/objects in a directory then you can use DIR to loop through the
contents of a directory and write them all to your table. Then format
the field in your form(s) as a hyperlink, and away you go.
Remember, Access databases can only be 2GB, and if you stuff them with
OLE objects, you'll run out of space fast.

Nov 13 '05 #4

P: n/a
"Lyn" wrote
Are you saying that what I am
trying to do can't be done? (As
opposed to being not good
practice?)


The sample imaging databases at http://accdevel.tripod.com illustrate three
approaches to handling images in Access, and the download includes an
article discussing considerations in choosing an approach. Two of the
approaches do not use OLE Objects and, thus, avoid the database bloat, and
some other problems, associated with images in OLE Objects.

If you are printing the images in reports, to avoid memory leakage, you
should also see MVP Stephen Lebans' http://www.lebans.com/printfailures.htm.
PrintFailure.zip is an Access97 MDB containing a report that fails during
the Access formatting process prior to being spooled to the Printer Driver.
This MDB also contains code showing how to convert the contents of the Image
control to a Bitmap file prior to printing. This helps alleviate the "Out of
Memory" error that can popup when printing image intensive reports.

Larry Linson
Microsoft Access MVP
Nov 13 '05 #5

P: n/a
Lyn
"Larry Linson" <bo*****@localhost.not> wrote in message
news:fUrse.4029$kj5.1656@trnddc03...
"Lyn" wrote
Are you saying that what I am
trying to do can't be done? (As
opposed to being not good
practice?)


The sample imaging databases at http://accdevel.tripod.com illustrate
three
approaches to handling images in Access, and the download includes an
article discussing considerations in choosing an approach.


Thanks guys,
I shall consider your comments and reference weblinks, then maybe rethink my
approach.

The main reason I was embedding the pictures was that this will be a
small(ish) database with hobbyist users, and I thought that keeping the
whole thing packaged within the one .mdb file was better than risking links
being broken by amateur users.

However, all that you have said makes sense and I now need to weigh up the
relative merits before making a final decision.

--
Cheers,
Lyn.
Nov 13 '05 #6

This discussion thread is closed

Replies have been disabled for this discussion.