D
drew_s
Guest
I am using an Access front end attached to a MSQL database and am trying to use "appendchunk" to copy
a photograph into a binary field in the database.
I am using the ADO process to do this and have created a recordset to locate the record (existing) into which
wish to save the photo.
This seems to work fine until I get to the line "T!Pic.appendchunk Datasource", where "T" is the recordset, "Pic"
is a field in the recordset and "datasource" is the binary data.
At this point I get the error message "operation not allowed in this context". I can only think that my reference to the field in
which the data is to be stored "T!Pic" is incorrect, but i am at a loss to know how to fix it.
Can anyone help
Relevent Code
a photograph into a binary field in the database.
I am using the ADO process to do this and have created a recordset to locate the record (existing) into which
wish to save the photo.
This seems to work fine until I get to the line "T!Pic.appendchunk Datasource", where "T" is the recordset, "Pic"
is a field in the recordset and "datasource" is the binary data.
At this point I get the error message "operation not allowed in this context". I can only think that my reference to the field in
which the data is to be stored "T!Pic" is incorrect, but i am at a loss to know how to fix it.
Can anyone help
Relevent Code
Code:
Private Sub Command40_Click()
Dim Source As String
Dim T As ADODB.Recordset
Set T = New ADODB.Recordset
'Dim SField As String
Dim SQLT As String
'Dim F As String
T.ActiveConnection = CurrentProject.Connection
T.CursorType = adOpenKeyset
T.LockType = adLockOptimistic
Source = "C:\Documents and Settings\Owner\My Documents\My Pictures\QuickCam\Album\Pictures and Videos\Pictures\Drew.jpg"
SQLT = "SELECT PID,Pic FROM tblNames Where PID = '1000'"
'SField = "Pic"
T.Open SQLT
Dim NumBlocks As Integer, SourceFile As Integer, i As Integer
Dim FileLength As Long, LeftOver As Long
Dim FileData As String
Dim RetVal As Variant
SourceFile = FreeFile
Open Source For Binary Access Read As SourceFile
' Get the length of the file.
FileLength = LOF(SourceFile)
If FileLength = 0 Then
Exit Sub
End If
' Calculate the number of blocks to read and leftover bytes.
NumBlocks = FileLength \ Blocksize
LeftOver = FileLength Mod Blocksize
' SysCmd is used to manipulate status bar meter.
RetVal = SysCmd(acSysCmdInitMeter, "Reading BLOB", _
FileLength \ 1000)
' Read the leftover data, writing it to the table.
FileData = String$(LeftOver, 32)
Get SourceFile, , FileData
T!Pic.AppendChunk (FileData)
RetVal = SysCmd(acSysCmdUpdateMeter, LeftOver / 1000)
' Read the remaining blocks of data, writing them to the table.
FileData = String$(Blocksize, 32)
For i = 1 To NumBlocks
Get SourceFile, , FileData
T(SField).AppendChunk (FileData)
RetVal = SysCmd(acSysCmdUpdateMeter, Blocksize * i / 1000)
Next i
' Update the record and terminate function.
T.Update
RetVal = SysCmd(acSysCmdRemoveMeter)
Close SourceFile
Exit Sub
Exit Sub
End Sub
Last edited: