Hi
I've had a similar problem with DAO 3.51.
I was using a temporary file for storing images retrived with getchunk from
the SQL Server or MS Access before displaying it.
After few hours of testing I've noticed that the "errorous" behavior was
coused by type of buffer used to receive data. After declaring it as an
array of bytes instead of array of strings "error" dissapeared. This was
coused by Unicode conversion of the string buffer written to file.
Now the procedures looks like this:
Public Function CopyFieldToFile(fd As Field) As String
Dim tmpFileName As String
Dim FileNum As Integer
Dim Buffer() As Byte
Dim BytesNeeded As Long
Dim Buffers As Long
Dim Remainder As Long
Dim Offset As Long
Dim r As Integer
Dim i As Long
Static Count As Long
BytesNeeded = fd.FieldSize
If BytesNeeded > 0 Then
' Calculate the number of buffers needed to copy
Buffers = BytesNeeded \ ChunkSize
Remainder = BytesNeeded Mod ChunkSize
' Get a unique, temporary filename:
Count = Count + 1
tmpFileName = App.path & "\tmp" & Count & ".tif"
If Dir(tmpFileName) <> "" Then
Kill tmpFileName
End If
' Copy the bitmap to the temporary file chunk by chunk:
FileNum = FreeFile
Open tmpFileName For Binary As #FileNum
For i = 0 To Buffers - 1
ReDim Buffer(ChunkSize)
Buffer = fd.GetChunk(Offset, ChunkSize)
Put #FileNum, , Buffer()
Offset = Offset + ChunkSize
Next
' Copy the remaining chunk of the bitmap to the file:
ReDim Buffer(Remainder)
Buffer = fd.GetChunk(Offset, Remainder)
Put #FileNum, , Buffer()
Close #FileNum
End If
CopyFieldToFile = Trim(tmpFileName)
End Function
Private Sub CopyFileToField(FileName As String, fd As Field)
Dim ChunkSize As Long
Dim FileNum As Integer
Dim Buffer() As Byte
Dim BytesNeeded As Long
Dim Buffers As Long
Dim Remainder As Long
Dim i As Long
If Len(FileName) = 0 Then
Exit Sub
End If
If Dir(FileName) = "" Then
Err.Raise vbObjectError, , "Nie odnaleziono pliku: """ & FileName &
""""
End If
ChunkSize = 65536
FileNum = FreeFile
Open FileName For Binary As #FileNum
BytesNeeded = LOF(FileNum)
Buffers = BytesNeeded \ ChunkSize
Remainder = BytesNeeded Mod ChunkSize
For i = 0 To Buffers - 1
ReDim Buffer(ChunkSize)
Get #FileNum, , Buffer
fd.AppendChunk Buffer
Next
ReDim Buffer(Remainder)
Get #FileNum, , Buffer
fd.AppendChunk Buffer
Close #FileNum
End Sub
Happy programing
>I have a VB 5.0 application which uses DAO and AppendChunk/GetChunk to
>store/retrieve bitmaps in an Access/JET database. I have the application
>running on two different PCs: one has Windows 95, VB 5.0, and Office 97
>(including Access) installed on it; the other has Windows 98 and VB 5.0,
but
>not Office/Access. I have a database in which I stored some bitmap images
>from the application running on one machine, and some images from the
>application running on the other machine. When I try to read the data from
>the Long Binary field into Image controls (via GetChunk), I can only see
the
>images which were stored in the database by the app on the same machine --
>the others are completely garbled. When I read the images into the
controls
>from the app running on the other machine, it's the same problem -- now I
>can only see the images which were also saved from that machine. Those
>images which were saved from the other machine are garbled.
>Anyone have any ideas?
>I have SP-3 installed on both machines. It seems the only difference is
>Windows 95 vs. 98; and whether or not Office/Access is installed.
>Thanks in advance for the help!!