473,404 Members | 2,114 Online
Bytes | Software Development & Data Engineering Community
Post Job

Home Posts Topics Members FAQ

Join Bytes to post your question to a community of 473,404 software developers and data experts.

Trouble copying a picture object from one table to another

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
5 3457
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
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
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
"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
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 thread has been closed and replies have been disabled. Please start a new discussion.

Similar topics

1
by: Matt Evans | last post by:
Hi, this must have been asked for before, but I cannot see it. Hopefully this is very simple. I have a form which shows everything from a table. In this table is a picture field called photo....
2
by: wisaac | last post by:
What I would like to do is automate the manual process of copying an image from an excel spreadsheet to the clipboard, and pasting it into an access table with an OLE Object field. I want to do...
5
by: Steve | last post by:
Hi Can anyone tell me if it is possible to save a picture stored in an OLE objects on a form (bound object frame / unbound object frame) to a file. I have seen a command SavePicture Picture as...
3
by: abspring | last post by:
Hi I am a technology teacher/support person at an elementary school. I have created a database in which I need to insert a picture for each of our 650+ students. I have a table of student...
1
by: Jeremy.Campbell | last post by:
I am trying to add a picture to a form that is visible depending on certain criteria. The picture works perfectly on my computer, but on other users computers this image is either black or...
1
by: davidwelli | last post by:
Hello, I have a Access 200 format database that contains contact details and a picture for each record. The contact details are held in one table and the images are held in another as OLE...
1
by: =?Utf-8?B?Y3JhbmtlX2JveQ==?= | last post by:
Hi Folks, I'm not sure where this post belongs since I'm using managed vc.net, but the issue is around GDI BitBlt. Here is a summary of the problem: - I am trying to copy a bitmap of my main...
2
by: raylopez99 | last post by:
Beware newbies: I spent a day before I figured this out: copying a bitmap (image) file to file is not quite like copying a text file--you have to do some tricks (see below), like using a...
5
matheussousuke
by: matheussousuke | last post by:
Hello, I'm using tiny MCE plugin on my oscommerce and it is inserting my website URL when I use insert image function in the emails. The goal is: Make it send the email with the URL...
0
by: Charles Arthur | last post by:
How do i turn on java script on a villaon, callus and itel keypad mobile phone
0
by: emmanuelkatto | last post by:
Hi All, I am Emmanuel katto from Uganda. I want to ask what challenges you've faced while migrating a website to cloud. Please let me know. Thanks! Emmanuel
0
BarryA
by: BarryA | last post by:
What are the essential steps and strategies outlined in the Data Structures and Algorithms (DSA) roadmap for aspiring data scientists? How can individuals effectively utilize this roadmap to progress...
1
by: nemocccc | last post by:
hello, everyone, I want to develop a software for my android phone for daily needs, any suggestions?
1
by: Sonnysonu | last post by:
This is the data of csv file 1 2 3 1 2 3 1 2 3 1 2 3 2 3 2 3 3 the lengths should be different i have to store the data by column-wise with in the specific length. suppose the i have to...
0
marktang
by: marktang | last post by:
ONU (Optical Network Unit) is one of the key components for providing high-speed Internet services. Its primary function is to act as an endpoint device located at the user's premises. However,...
0
Oralloy
by: Oralloy | last post by:
Hello folks, I am unable to find appropriate documentation on the type promotion of bit-fields when using the generalised comparison operator "<=>". The problem is that using the GNU compilers,...
0
jinu1996
by: jinu1996 | last post by:
In today's digital age, having a compelling online presence is paramount for businesses aiming to thrive in a competitive landscape. At the heart of this digital strategy lies an intricately woven...
0
agi2029
by: agi2029 | last post by:
Let's talk about the concept of autonomous AI software engineers and no-code agents. These AIs are designed to manage the entire lifecycle of a software development project—planning, coding, testing,...

By using Bytes.com and it's services, you agree to our Privacy Policy and Terms of Use.

To disable or enable advertisements and analytics tracking please visit the manage ads & tracking page.