Appendchunkpublic function savefiletoDB (Byval FileName As String, DBField As Adod.field, Optional
Packagesize As long = 8192 &) as long
ON Error Goto Errhandle
Dim Lngctualsize As Long, LNGCurrentsize As Long
DIM BTEMP () AS BYTE
DIM HFILE AS Long
DIM I as integer
DIM LCHUNKCOUNT AS Long
DIM LCHUNKREMAINDER AS Long
LNGACTUALSIZE = Filelen (filename)
LNGCurrentsize = 0
IF lngactualsize <= 0 THEN
Err.raise err_size_equ_or_less_zero, "WriteFileToDB"
END IF
'Read file content
Hfile = freefile ()
Open filename for binary as hfile
Redim Btemp (package) 'temporary storage
Lchunkcount = Lof (Hfile) / packagesize '
LchunkRemainder = Lof (HFile) Mod packagesize
IF LCHUNKREMAINDER> 0 Then Lchunkcount = LCHUNKCOUNT 1
For i = 1 to lchunkcount
Get Hfile, Btemp 'removes a piece from the file
DBField.Appendchunk (btemp) 'Write the block in the field
NEXT
Close # 1
SavefiletoDB = 0
EXIT FUNCTION
Errhandle:
SaveFiletoDB = Err.Number
END FUNCTION