473,659 Members | 2,632 Online
Bytes | Software Development & Data Engineering Community
+ Post

Home Posts Topics Members FAQ

Error with AppendChunk() and MEMO field

Hello.

I am attempting to use AppendChunk() to write binary data to a memo field
in Access 2000. My initial call to AppendChunk() results in a data type
conversion error. Any suggestions? Here is a VBA function which demonstrates
the problem.

Thanks
-Mark

Public Function appendchunk_fai l_test() As Boolean
On Error GoTo appendchunk_fai l_test_ERROR
appendchunk_fai l_test = True
Dim sStmt As String
Dim sFilename As String
Dim chunk() As Byte
Dim lSize As Long
Dim nHandle As Integer

sFilename = InputBox("Enter a binary file name")
nHandle = FreeFile
Open sFilename For Binary Access Read As nHandle
lSize = LOF(nHandle)

'For test purposes, just write a single small chunk
If lSize < 2048 Then Err.Raise 5002, "appendchunk_fa il_test()", "Please
select a larger binary file"
ReDim chunk(2048)
Get nHandle, , chunk()
Close nHandle

'Got our test chunk. Now create temporary table
Dim db As DAO.Database
Dim tbl As DAO.TableDef
Dim fld As DAO.Field
Dim rs As DAO.Recordset
Const csTable = "__TEST__"

Set db = CurrentDb()
Set tbl = db.CreateTableD ef(csTable)
Set fld = tbl.CreateField ("pkid", vbLong)
tbl.Fields.Appe nd fld
Set fld = Nothing
Set fld = tbl.CreateField ("photo_stream" , dbMemo)
tbl.Fields.Appe nd fld
Set fld = Nothing
db.TableDefs.Ap pend tbl
Set tbl = Nothing

sStmt = "SELECT pkid, photo_stream FROM " & csTable
Set rs = db.OpenRecordse t(sStmt, dbOpenDynaset)
rs.AddNew
rs!pkid = 1
'DATA TYPE CONVERSION ERROR raised with next statement
rs.Fields("phot o_stream").Appe ndChunk chunk()
rs.Close
Set rs = Nothing

'Delete temporary table
db.TableDefs.De lete csTable
Set db = Nothing

appendchunk_fai l_test_ERROR:
appendchunk_fai l_test = False
MsgBox "Error #" & Err.Number & vbCrLf & Err.description , ,
"appendchunk_fa il_test()"
GoTo appendchunk_fai l_test_EXIT

appendchunk_fai l_test_EXIT:

End Function
Mar 7 '06 #1
16 4874

"Mark" <no****@thanksa nyway.org> wrote in message
news:4e******** *************** *******@w-link.net...
Hello.

I am attempting to use AppendChunk() to write binary data to a memo field
in Access 2000. My initial call to AppendChunk() results in a data type
conversion error. Any suggestions? Here is a VBA function which
demonstrates
the problem.

Thanks
-Mark

Public Function appendchunk_fai l_test() As Boolean
On Error GoTo appendchunk_fai l_test_ERROR
appendchunk_fai l_test = True
Dim sStmt As String
Dim sFilename As String
Dim chunk() As Byte
Dim lSize As Long
Dim nHandle As Integer

sFilename = InputBox("Enter a binary file name")
nHandle = FreeFile
Open sFilename For Binary Access Read As nHandle
lSize = LOF(nHandle)

'For test purposes, just write a single small chunk
If lSize < 2048 Then Err.Raise 5002, "appendchunk_fa il_test()", "Please
select a larger binary file"
ReDim chunk(2048)
Get nHandle, , chunk()
Close nHandle

'Got our test chunk. Now create temporary table
Dim db As DAO.Database
Dim tbl As DAO.TableDef
Dim fld As DAO.Field
Dim rs As DAO.Recordset
Const csTable = "__TEST__"

Set db = CurrentDb()
Set tbl = db.CreateTableD ef(csTable)
Set fld = tbl.CreateField ("pkid", vbLong)
tbl.Fields.Appe nd fld
Set fld = Nothing
Set fld = tbl.CreateField ("photo_stream" , dbMemo)
tbl.Fields.Appe nd fld
Set fld = Nothing
db.TableDefs.Ap pend tbl
Set tbl = Nothing

sStmt = "SELECT pkid, photo_stream FROM " & csTable
Set rs = db.OpenRecordse t(sStmt, dbOpenDynaset)
rs.AddNew
rs!pkid = 1
'DATA TYPE CONVERSION ERROR raised with next statement
rs.Fields("phot o_stream").Appe ndChunk chunk()
rs.Close
Set rs = Nothing

'Delete temporary table
db.TableDefs.De lete csTable
Set db = Nothing

appendchunk_fai l_test_ERROR:
appendchunk_fai l_test = False
MsgBox "Error #" & Err.Number & vbCrLf & Err.description , ,
"appendchunk_fa il_test()"
GoTo appendchunk_fai l_test_EXIT

appendchunk_fai l_test_EXIT:

End Function


If you look at the help file for the AppendChunk Method it states:
"...Appends data from a string expression to a Memo or Long Binary Field
object in a Recordset."
but you are trying to use an array of bytes.

There is an example given at:
http://support.microsoft.com/?kbid=210486
which shows a file being stored in, and read from, a table.

There are other basic issues you have wrong here - the error handling for
instance is not properly structured. A more fundemental issue is the
underlying wisdom of storing binary files in a table - why not just store
the paths in the db?
Mar 7 '06 #2
"Anthony England" <ae******@oops. co.uk> wrote:

If you look at the help file for the AppendChunk Method it states:
"...Appends data from a string expression to a Memo or Long Binary Field
object in a Recordset."
but you are trying to use an array of bytes.
I have seen numerous examples on the Web that use an array of bytes,
but of course that doesn't mean they are correct or that they were
even tested. I'll try it with a fixed-length string.

There are other basic issues you have wrong here - the error handling for
instance is not properly structured.
Can you be more specific? My error handling seems to be working fine.

A more fundemental issue is the underlying wisdom of storing binary files
in a table - why not just store the paths in the db?


My project will store information about a large number of photographs.
My issue with storing only the file paths has to do with creating a database
whose informational integrity is wholly dependant upon an external data
repository (a host computer's file system and the file hierarchy.) If the
file
hierarchy is damaged or changed, or if the database is separated from the
host containing the matching file hierarchy, then the database becomes
useless.

My solution to this is to place a small thumbnail (approx 15-30kb)
of the photograph into the database. The database would also include the
path and filename of the full-resolution image(s).

An additional feature I am considering is to create a checksum of each
file and include the checksum with the database record. This could be
useful if it were necessary to programmaticall y re-establish the links
from the database to the external file system.

-Mark


Mar 7 '06 #3
"Mark" <no****@thanksa nyway.org> wrote:
I have seen numerous examples on the Web that use an array of bytes,
but of course that doesn't mean they are correct or that they were
even tested. I'll try it with a fixed-length string.
And now it appears to work. Thanks!

Can you be more specific? My error handling seems to be working fine.


Ok, yeah, I see I left out the final "appendchunk_fa il_test_EXIT", so my
code would have run over into the error handler when it reached the bottom.
That was an oversight in throwing together this sample code. It never got
that far so I didn't notice.

Thanks again
-Mark
Mar 7 '06 #4

"Mark" <no****@thanksa nyway.org> wrote in message
news:UI******** ************@w-link.net...
"Mark" <no****@thanksa nyway.org> wrote:
I have seen numerous examples on the Web that use an array of bytes,
but of course that doesn't mean they are correct or that they were
even tested. I'll try it with a fixed-length string.


And now it appears to work. Thanks!

Can you be more specific? My error handling seems to be working fine.


Ok, yeah, I see I left out the final "appendchunk_fa il_test_EXIT", so my
code would have run over into the error handler when it reached the
bottom.
That was an oversight in throwing together this sample code. It never got
that far so I didn't notice.

Thanks again
-Mark


This is the way I structure a standard sub with error handling. Note that
the Exit bit comes above the Error bit, so normally if there is no error the
sub follows the flow straight down and exits before the Error bit. This is
not quite like yours.
Notice also that even if an error occurs, my code still tries to clean up -
and this is what you should have done with opening and closing the file.
You open the file, but if an error occurs (as with the AppendChunk) you make
no effort to close the file again. In other words - you should try and
close the file in the Exit bit so the code always runs regardless of whether
an error occurred.
Private Sub MySub()

On Error GoTo Err_Handler

Dim dbs As DAO.Database
Dim rst As DAO.Recordset
Dim strSQL As String

strSQL = "SELECT * FROM MyTable ORDER BY MyField"

Set dbs = CurrentDb

Set rst = dbs.OpenRecords et(strSQL)

While Not rst.EOF
rst.MoveNext
Wend

MsgBox "Done", vbInformation

Exit_Handler:

If Not rst Is Nothing Then
rst.Close
Set rst = Nothing
End If

If Not dbs Is Nothing Then
Set dbs = Nothing
End If

Exit Sub

Err_Handler:
MsgBox Err.Description , vbExclamation, "Error No: " & Err.Number
Resume Exit_Handler

End Select

End Sub
Mar 7 '06 #5
Bri
Mark wrote:
My project will store information about a large number of photographs.
My issue with storing only the file paths has to do with creating a database
whose informational integrity is wholly dependant upon an external data
repository (a host computer's file system and the file hierarchy.) If the
file
hierarchy is damaged or changed, or if the database is separated from the
host containing the matching file hierarchy, then the database becomes
useless.

My solution to this is to place a small thumbnail (approx 15-30kb)
of the photograph into the database. The database would also include the
path and filename of the full-resolution image(s).


I've been bashing around ideas for a similar database. My own digital
photos have grown to the point that I don't store them on the PC. Once I
get to enough for a CD, I burn them onto two CDs (always have a
backup!). My problem has always been; what to do about thumbnails. Are
you using code in your db to create the thumbnails or do you have some
other app that you manually create them from? If you are imbedding them
into a Memo field, how are you displaying them?

Thanks for any insight you can give me on this.

--
Bri

Mar 8 '06 #6
"Bri" <no*@here.com > wrote:

My problem has always been; what to do about thumbnails. Are you using
code in your db to create the thumbnails or do you have some other app
that you manually create them from? If you are imbedding them into a Memo
field, how are you displaying them?


I'm afraid that my answers to your questions are "dunno" and "dunno."
I have not yet implemented this feature, so I haven't explored options
for a VBA-based reduction of the images to JPEG thumbnails.
I notice that Paint Shop Pro v7 (which is installed on my system)
appears as an OLE automation server, so that is one possibility.
or I may use Irfanview* to generate the thumbnails and then write
some VBA code to load them into the database.

I believe that an OLE Object field may be more appropriate than
a Memo field for storing this data (and I subsequently discovered that
AppendChunk() does work with a byte array if the data is being
appended to an Ole Object field.) There should be a way to display
the binary stream in a VB image control, although I have not found
it yet. If all else fails, I suppose I could write out the stream to a
temporary file and then use LoadPicture to display it in an Image
control.

-Mark
*http://www.irfanview.com is shareware and is the best tool I have
found so far or batch manipulation of image files. No financial
interest, just a happy user, blah blah etc.


Mar 8 '06 #7
Bri


Mark wrote:
"Bri" <no*@here.com > wrote:
My problem has always been; what to do about thumbnails. Are you using
code in your db to create the thumbnails or do you have some other app
that you manually create them from? If you are imbedding them into a Memo
field, how are you displaying them?

I'm afraid that my answers to your questions are "dunno" and "dunno."
I have not yet implemented this feature, so I haven't explored options
for a VBA-based reduction of the images to JPEG thumbnails.
I notice that Paint Shop Pro v7 (which is installed on my system)
appears as an OLE automation server, so that is one possibility.
or I may use Irfanview* to generate the thumbnails and then write
some VBA code to load them into the database.

I believe that an OLE Object field may be more appropriate than
a Memo field for storing this data (and I subsequently discovered that
AppendChunk() does work with a byte array if the data is being
appended to an Ole Object field.) There should be a way to display
the binary stream in a VB image control, although I have not found
it yet. If all else fails, I suppose I could write out the stream to a
temporary file and then use LoadPicture to display it in an Image
control.

-Mark
*http://www.irfanview.com is shareware and is the best tool I have
found so far or batch manipulation of image files. No financial
interest, just a happy user, blah blah etc.


Ah, so you are not any further along in this than I am. :{(
My version of PSP is 4 and I don't see any exposed objects for it. I
have Irfanview, but didn't like it as much as PSP, so I really haven't
used it a lot. I've been exploring another free app called XNview
(http://www.xnview.com/). He has a developer kit available, but I
haven't looked that closely a it yet. It has batch image manipulation
capability and I have been creating my thumbnails in bulk with that. I
have then been linking to them with an image control rather than
embedding them into a table. This means you can lose a thumbnail (just
like you can lose the full image), but the total size is a lot less than
with embedding. Access adds in a huge amount of overhead to store images
in OLE Object fields.

--
Bri

Mar 9 '06 #8
"Bri" <no*@here.com > wrote:

Ah, so you are not any further along in this than I am. :{(
My version of PSP is 4 and I don't see any exposed objects for it. I have
Irfanview, but didn't like it as much as PSP, so I really haven't used it
a lot.
Don't write off Irfanview. Unlike PSP it is not an image editor.
But it does have very good features for batch processing, and that
is what I use it for.
I have then been linking to them with an image control rather than
embedding them into a table. This means you can lose a thumbnail (just
like you can lose the full image), but the total size is a lot less than
with embedding. Access adds in a huge amount of overhead to store images
in OLE Object fields.


Is this peculiar to the OLE Object field, or would the Memo field
exhibit the same problem? Assuming that a binary stream can be
stored in a memo field, that might be a suitable way to store a small
(<65k) jpeg thumbnail.

Unfortunately, database size will grow substantially if images are
stored in the database. It is definitely a tradeoff. IMHO it may be
workable if only small renditions are stored in the database.
Of course you will still have quite a bit of work to do if you lose
your links to the external full-resolution images, but at least you
will have the db-based thumbnails to guide you in restoring the
links.

I proposed a checksum-based method to help solidify the links
to the external images. This would entail generating a unique
checksum value for each full-resolution image, and storing that
value in the database record. If the external links were lost,
the checksums could make it possible to programmaticall y
re-establish the external links by re-generating checksums
for the external images and matching them to the checksums
in the database. Obviously this is not foolproof, but it could
be quite helpful in disaster recovery.

-Mark

Mar 9 '06 #9
bob

Is this peculiar to the OLE Object field
The huge overhead is peculiar to OLE Embedding (and OLE Linking) – these are front-end techniques rather
than field types. OLE Embedding and Linking require a binary field; in Access this is the OLE Object field
type, but the problem is not with the field type (which really has nothing to do with OLE, it’s just a
binary field - the same problem occurs if you use OLE Embedding/Linking with binary fields in other databases,
such as the ‘Image’ field type in SQL Server).

You can store binary data in an OLE Object field directly, without using OLE Embedding, then there is no
such overhead (and various other problems are avoided too). Done this way, allowing 4k for each thumbnail,
the database could handle 500,000 thumbnails.

Memo fields are designed for text, not binary data.
I proposed a checksum-based method to help solidify the links
How could your ‘links’ be lost? If you store enough of the path and the filename to uniquely identify
the file that’s all you need; you don’t need to calculate checksums, no ‘programmatic re-establishment’
of links would be required.

For example, if your photos are stored as follows:

D:\photos\2002-12-04\PC221788.JPG

You could store ‘2002-12-04\PC221788.JPG ’ as your link (you may want to split this between 2 fields).
This is enough to uniquely identify the file, and you can easily move the file to a new root without needing
to change any records.

--
_______________ _______________ _______________ __________
DBPix 2.0: Add pictures to Access, Easily & Efficiently
http://www.ammara.com/dbpix/access.html

"Mark" <no****@thanksa nyway.org> wrote:"Bri" <no*@here.com > wrote:

Ah, so you are not any further along in this than I am. :{(
My version of PSP is 4 and I don't see any exposed objects for it. I have
Irfanview, but didn't like it as much as PSP, so I really haven't used it
a lot.


Don't write off Irfanview. Unlike PSP it is not an image editor.
But it does have very good features for batch processing, and that
is what I use it for.
I have then been linking to them with an image control rather than
embedding them into a table. This means you can lose a thumbnail (just
like you can lose the full image), but the total size is a lot less than
with embedding. Access adds in a huge amount of overhead to store images
in OLE Object fields.


Is this peculiar to the OLE Object field, or would the Memo field
exhibit the same problem? Assuming that a binary stream can be
stored in a memo field, that might be a suitable way to store a small
(<65k) jpeg thumbnail.

Unfortunatel y, database size will grow substantially if images are
stored in the database. It is definitely a tradeoff. IMHO it may be
workable if only small renditions are stored in the database.
Of course you will still have quite a bit of work to do if you lose
your links to the external full-resolution images, but at least you
will have the db-based thumbnails to guide you in restoring the
links.

I proposed a checksum-based method to help solidify the links
to the external images. This would entail generating a unique
checksum value for each full-resolution image, and storing that
value in the database record. If the external links were lost,
the checksums could make it possible to programmaticall y
re-establish the external links by re-generating checksums
for the external images and matching them to the checksums
in the database. Obviously this is not foolproof, but it could
be quite helpful in disaster recovery.

-Mark


Mar 10 '06 #10

This thread has been closed and replies have been disabled. Please start a new discussion.

Similar topics

4
10790
by: Philipp Lenssen | last post by:
This drives me crazy: I have a file upload script to save an image on the disk (and later on in the database)... it used to work and now it doesn't, though I didn't change anything within the file upload script itself. The file-uploader was originally written by Jacob Gilley and I get the following error: Microsoft VBScript runtime error '800a0005' Invalid procedure call or argument cls-file-uploader.asp, line 139
3
2160
by: Fardude | last post by:
I have a few tables in SQL Server 2000 and a small Access 97 that has linked tables used to insert/update/delete into SQL Server 2k tables. Everything works fine except Updating one of these table through Access, I get "Write conflict error" which basicaly says since you have updated this record some other user has updated it. I know for sure this is not True, becuase noone else has access t this database. This does not happen to any...
0
1375
by: Lauren Wilson | last post by:
The error does not have an error number. It's not even a normal Access error message box. Hope someone has some insight to this problem. I have a form that contains a large (5" x 4") text box bound to a memo field. This field allows users to type in the text of an email to be sent through Outlook (via automation). I ONE user who send me his back end data base where he has inserted several two - three page emails. When scrolling...
1
2258
by: Andrew Donnelly | last post by:
I am trying to update a memo field in a table from a form that I have created. The form is unbound, and once the user makes their changes, they have to click the continue button. Once the button is click then, there is some VB code that uses SQL Update to take the information on the form and update the table with the new changes. However, I am having issues with the Memo fields. I have looked at several different posts and have not been...
3
1986
by: MLH | last post by:
If Err.Number = 2001 Then I have the above line in a procedure I downloaded. I don't know what error that is exactly.
8
12473
by: PW | last post by:
Hi, There is code in Alison Balter's excellant "Mastering Access 2003" to create a list of error codes and descriptions but it only generates error messages 3 through 94. Is there a website with a list of all of the error messages (with descriptions?). Thanks, -paul
9
5731
by: RMC | last post by:
Hello, I'm looking for a way to parse/format a memo field within a report. The Access 2000 database (application) has an equipment table that holds a memo field. Within the report, the memo field is printed within the detailed area. The problem is, the apllication is not setup properly, thus the users are entering data within the memo field as: location1 1/1/2005 1/1/2006
2
1924
by: LEX | last post by:
Could not update; currently locked by another session on this machine. Can someone help me figure out why access gives me this error on some record's memo fields but not on others?
2
3147
by: RLN | last post by:
Luke Chung at FMS Inc provide this link in another thread that provided a really helpful .pdf file error listing: http://www.fmsinc.com/MicrosoftAccess/Errors/ErrorNumberAccess2007-2000. pdf Does anyone have a VBA example where an error reference table contains the error numbers and description of the errors listed in Luke's document? Thanks.
0
8428
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, people are often confused as to whether an ONU can Work As a Router. In this blog post, we’ll explore What is ONU, What Is Router, ONU & Router’s main usage, and What is the difference between ONU and Router. Let’s take a closer look ! Part I. Meaning of...
0
8851
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, it seems that the internal comparison operator "<=>" tries to promote arguments from unsigned to signed. This is as boiled down as I can make it. Here is my compilation command: g++-12 -std=c++20 -Wnarrowing bit_field.cpp Here is the code in...
0
8751
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 tapestry of website design and digital marketing. It's not merely about having a website; it's about crafting an immersive digital experience that captivates audiences and drives business growth. The Art of Business Website Design Your website is...
1
8535
by: Hystou | last post by:
Overview: Windows 11 and 10 have less user interface control over operating system update behaviour than previous versions of Windows. In Windows 11 and 10, there is no way to turn off the Windows Update option using the Control Panel or Settings app; it automatically checks for updates and installs any it finds, whether you like it or not. For most users, this new feature is actually very convenient. If you want to control the update process,...
0
7360
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, and deployment—without human intervention. Imagine an AI that can take a project description, break it down, write the code, debug it, and then launch it, all on its own.... Now, this would greatly impact the work of software developers. The idea...
0
4338
by: adsilva | last post by:
A Windows Forms form does not have the event Unload, like VB6. What one acts like?
1
2757
by: 6302768590 | last post by:
Hai team i want code for transfer the data from one system to another through IP address by using C# our system has to for every 5mins then we have to update the data what the data is updated we have to send another system
2
1982
muto222
by: muto222 | last post by:
How can i add a mobile payment intergratation into php mysql website.
2
1739
bsmnconsultancy
by: bsmnconsultancy | last post by:
In today's digital era, a well-designed website is crucial for businesses looking to succeed. Whether you're a small business owner or a large corporation in Toronto, having a strong online presence can significantly impact your brand's success. BSMN Consultancy, a leader in Website Development in Toronto offers valuable insights into creating effective websites that not only look great but also perform exceptionally well. In this comprehensive...

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.