DAO getchunk/appendchunk problems in Access 97 DB 
Author Message
 DAO getchunk/appendchunk problems in Access 97 DB

A big thank you to anyone who can help!

I have a program that tracks personal information for employees and stores
this information in a Access97 database using DAO. I also take a picture of
the employee and include it in the database. The object is to store this
info and print a badge and personnel form. When the info is originally
collected, the data is collected and prints just fine. The problem occurs
either in my saving the picture OR retrieving the picture from my database.

I am  using the getchunk and appendchunk methods to store and retrieve the
photo from an OLE field in my database (code included below). All other data
is saved and retrieved from the databse just fine. The picture however is
causing me major gripes!

Based on the size growth of the database, it seems that the picture is being
stored, but I can't retieve the info and I don't know whether or not the
correct picture is being saved. Let me explain. I created a form to simply
scroll through each record in the DB. The first record loads and I disply
the picture just fine. As I move through the databse, all information is
updated correctly, except the picture. The same (or similar) picture is
displayed all of the time. I say same or similar because I write the picture
to a temporary file and then load it on my form. As I check the creation
date of the file, it is definitely being updated as I scroll through the
file. Another interesting thing is that the picture size for the first
record is 230,470 bytes, and in each subsequent record, the file size
increases by exactly 1 byte.

I'm stumped and the client is getting grouchy. I am sure that I am missing
something obvious, but I am to the point that I can't even read my own code.

Any help is greatly appreciated.

TIA

Doug

'************************************************************
' Here is where I begin to play around with the getchunk
' and appendchunk methods to save and retrieve a
' picture to and from a database
'************************************************************
'Saving the photo to the database
    Debug.Print "Entering write photo area."
    Dim strFileName As String
    strFileName = App.Path + "\Temp.bmp"
    Dim iFileNum As Integer
    iFileNum = FreeFile
    Dim iFileLength As Long
    Dim abBytes() As Byte
    Open strFileName For Binary Access Read As #iFileNum
    iFileLength = LOF(iFileNum)
    Debug.Print "Length of file is "; iFileLength
    ReDim abBytes(iFileLength)
    Get #iFileNum, , abBytes()
    tbInfo.Fields("Photo").AppendChunk (abBytes)
    Close iFileNum

' Retrieving the photo from the database

        Debug.Print "Entering read photo area"
        Dim stFileName As String
        Dim strFileName As String
        strFileName = App.Path + "\Temp.bmp"
        Dim iFileNum As Integer
        Dim iFileLength As Long
        Dim abBytes() As Byte
        iFileNum = FreeFile
        Open strFileName For Binary As #iFileNum
        iFileLength = LenB(tbInfo("Photo"))
        Debug.Print "Length of photo file is "; iFileLength
        ReDim abBytes(iFileLength)
        abBytes = tbInfo.Fields("Photo").GetChunk(0, iFileLength)
        Put #iFileNum, , abBytes()
        Close iFileNum
        End If

--
Where there's a Wills, there's a way!



Wed, 18 Jun 1902 08:00:00 GMT  
 DAO getchunk/appendchunk problems in Access 97 DB
Try not to get a whole chunk of the picture from database at once.

        Debug.Print "Entering read photo area"
        Dim stFileName As String
        Dim strFileName As String
        strFileName = App.Path + "\Temp.bmp"
        Dim iFileNum As Integer
        Dim iFileLength As Long

    ' Set size of chunk in bytes.
    Const conChunkSize = 32768

    Dim lngOffset As Long
    Dim lngTotalSize As Long
    Dim strChunk As String

        iFileNum = FreeFile
        Open strFileName For Binary As #iFileNum
       lngTotalSize = tbInfo("Photo").FieldSize

        Do While lngOffset < lngTotalSize
                strChunk = fldSource.GetChunk(lngOffset, conChunkSize)
               Put #iFileNum, , strChunk
               lngOffset = lngOffset + conChunkSize
        loop
        Close iFileNum

NOTE: I do not own any VB Compiler, I never try the code above.


Quote:
> A big thank you to anyone who can help!

> I have a program that tracks personal information for employees and stores
> this information in a Access97 database using DAO. I also take a picture
of
> the employee and include it in the database. The object is to store this
> info and print a badge and personnel form. When the info is originally
> collected, the data is collected and prints just fine. The problem occurs
> either in my saving the picture OR retrieving the picture from my
database.

> I am  using the getchunk and appendchunk methods to store and retrieve the
> photo from an OLE field in my database (code included below). All other
data
> is saved and retrieved from the databse just fine. The picture however is
> causing me major gripes!

> Based on the size growth of the database, it seems that the picture is
being
> stored, but I can't retieve the info and I don't know whether or not the
> correct picture is being saved. Let me explain. I created a form to simply
> scroll through each record in the DB. The first record loads and I disply
> the picture just fine. As I move through the databse, all information is
> updated correctly, except the picture. The same (or similar) picture is
> displayed all of the time. I say same or similar because I write the
picture
> to a temporary file and then load it on my form. As I check the creation
> date of the file, it is definitely being updated as I scroll through the
> file. Another interesting thing is that the picture size for the first
> record is 230,470 bytes, and in each subsequent record, the file size
> increases by exactly 1 byte.

> I'm stumped and the client is getting grouchy. I am sure that I am missing
> something obvious, but I am to the point that I can't even read my own
code.

> Any help is greatly appreciated.

> TIA

> Doug

> '************************************************************
> ' Here is where I begin to play around with the getchunk
> ' and appendchunk methods to save and retrieve a
> ' picture to and from a database
> '************************************************************
> 'Saving the photo to the database
>     Debug.Print "Entering write photo area."
>     Dim strFileName As String
>     strFileName = App.Path + "\Temp.bmp"
>     Dim iFileNum As Integer
>     iFileNum = FreeFile
>     Dim iFileLength As Long
>     Dim abBytes() As Byte
>     Open strFileName For Binary Access Read As #iFileNum
>     iFileLength = LOF(iFileNum)
>     Debug.Print "Length of file is "; iFileLength
>     ReDim abBytes(iFileLength)
>     Get #iFileNum, , abBytes()
>     tbInfo.Fields("Photo").AppendChunk (abBytes)
>     Close iFileNum

> ' Retrieving the photo from the database

>         Debug.Print "Entering read photo area"
>         Dim stFileName As String
>         Dim strFileName As String
>         strFileName = App.Path + "\Temp.bmp"
>         Dim iFileNum As Integer
>         Dim iFileLength As Long
>         Dim abBytes() As Byte
>         iFileNum = FreeFile
>         Open strFileName For Binary As #iFileNum
>         iFileLength = LenB(tbInfo("Photo"))
>         Debug.Print "Length of photo file is "; iFileLength
>         ReDim abBytes(iFileLength)
>         abBytes = tbInfo.Fields("Photo").GetChunk(0, iFileLength)
>         Put #iFileNum, , abBytes()
>         Close iFileNum
>         End If

> --
> Where there's a Wills, there's a way!



Wed, 18 Jun 1902 08:00:00 GMT  
 
 [ 2 post ] 

 Relevant Pages 

1. DAO getchunk/appendchunk problems in Access 97 DB

2. Access 97: VBA-DAO-Access 97 synchronization problem?

3. Weird problem with GetChunk/AppendChunk and BLOBs

4. Problem reading strings from Access7 using getchunk/appendchunk/string datatype

5. Weird problem with GetChunk/AppendChunk and BLOBs

6. Problem with ADO, Getchunk and Appendchunk in SQL7 and VB6

7. Weird problem with GetChunk/AppendChunk and BLOBs

8. Convert Access 97 db to Access 2000 db in VB6

9. Converting Access 2.0 DB to Access 97 DB in VB code

10. Excel 97, Access 97 and DAO

11. Access 97 DB Corruption Recurring Problem

12. Problem writing to Access 97 DB with ADO 1.5 and 2.1 (using ODBC)

 

 
Powered by phpBB® Forum Software