Problem with DAO rst("Field").FieldSize()

lgarcia3
05-18-2005, 06:36 PM
I am trying to retrieve all the files in a SQL Server image column and put them in a secured folder. I am using DAO for simplicity since I'm more familiar with it and this is a hot project. This application will not work for too long.

I have been having problems with this method in a DAO record set:

rst("Field").FieldSize()

It does not matter if the table has information or not it sometimes comes back with the right information and some other times does not.
Does anyone knows what is going on?
Thanks!

lgarcia3
05-18-2005, 06:49 PM
Ok, I just noticed something. If I read the file once from the blob, then it does not have anything for FileSize?? That's that means that I am deleting the file? I don't think so. This is what I am using to read the file. It is a very common example in MSDN docs.

Dim NumBlocks As Integer, DestFile As Integer, i As Integer
Dim FileLength As Long, LeftOver As Long
Dim FileData As String

On Error GoTo Err_WriteBLOB


' Get the size of the field.
FileLength = T(sField).FieldSize()
If FileLength = 0 Or FileLength < 0 Then
WriteBLOB = 0
Exit Function
End If

' Calculate number of blocks to write and leftover bytes.
NumBlocks = FileLength \ BlockSize
LeftOver = FileLength Mod BlockSize

' Remove any existing destination file.
DestFile = FreeFile
Open destination For Output As DestFile
Close DestFile

' Open the destination file.
Open destination For Binary As DestFile

' Write the leftover data to the output file.
FileData = T(sField).GetChunk(0, LeftOver)
Put DestFile, , FileData

' Write the remaining blocks of data to the output file.
For i = 1 To NumBlocks
' Reads a chunk and writes it to output file.
FileData = T(sField).GetChunk((i - 1) * BlockSize _
+ LeftOver, BlockSize)
Put DestFile, , FileData

Next i

Close DestFile
WriteBLOB = FileLength
Exit Function

EZ Archive Ads Plugin for vBulletin Copyright 2006 Computer Help Forum