Article ID: 199929
Article Last Modified on 1/23/2007
Dim yBinaryData() As Byte
Open "C:\MyFile.dat" For Binary As #1
ReDim yBinaryData(LOF(1)) As Byte
Get #1, , yBinaryData
Close #1
rs.Fields("MyData").AppendChunk yBinaryData
For databases with "corrupted" data already stored, you will need to extract the information on a Windows 98 or Windows NT 4.0 SP3 computer and restore it correctly using a byte array.
| Name | Type |
|---|---|
| ID (Primary Key) | AutoNumber |
| Picture | OLE Object |
Sub TestPicIn(sFileName As String)
Dim db As Database
Dim rs As Recordset
Dim sData As String
Dim nDataSize As Long
Set db = CurrentDb()
Set rs = db.OpenRecordset("BinData")
rs.AddNew
Open sFileName For Binary As #1
nDataSize = LOF(1)
sData = Space$(nDataSize)
Get #1, , sData
Close #1
rs!Picture.AppendChunk sData
rs.Update
End Sub
Sub TestPicOut(sFileName As String)
Dim db As Database
Dim rs As Recordset
Dim sData As String
Dim nDataSize As Long
Set db = CurrentDb()
Set rs = db.OpenRecordset("BinData")
If Not rs.EOF Then
nDataSize = rs!Picture.FieldSize
sData = rs!Picture.GetChunk(0, nDataSize)
Open sFileName For Binary As #2
Put #2, , sData
Close #2
End If
End Sub
TestPicIn "C:\Windows\Setup.bmp"
TestPicOut "C:\Windows\Temp\TestPic.bmp"
RESULT: The image file is mistakenly converted to Unicode format before being stored to the database. Although it will "decode" correctly if extracted on the same Windows 95 computer that stored the image, when the data is extracted to a file on a Windows 98 computer, the image "decodes" incorrectly causing the new file to appear corrupt.
153238 HOWTO: Use GetChunk and AppendChunk Methods of RDO Object
Keywords: kbautomation kbprb kbrdo KB199929