n1a2v3i3n
Programmer
- Jan 19, 2009
- 18
I am writing a code to input image to a access datebase where in the path of the image is stored in the database.
Below code gives me a runtime error 91 Object variable or with block variable not set.
Private Sub cmdAddImage_Click()
Dim objDB As Database
Dim rsImage As New adodb.Recordset
Dim lOffset As Long
Dim lSize As Long
Dim sPath As String
Dim nHandle As Integer
Dim lSubChunks As Long
Dim Chunk() As Byte
Dim nFragmentOffset As Integer
Dim i As Integer
Dim lChunks As Long
Dim lKey As Long
Dim sSQL As String
'On Error GoTo cmdAddImage_Click_Error
frmFileDialog.Show vbModal
If gsFileName <> "" Then
'lKey = InputBox("Please enter a Number (1..n) as a key to the image")
'i f lKey > 0 Then
'check if unique Key
' sSQL = "select * from images"
' sSQL = sSQL & " where myKey=" & lKey
' Set rsImage = objDB.OpenRecordset(sSQL, dbOpenDynaset)
' If Not rsImage.EOF Then
' MsgBox "Key is already in use"
' GoTo Exit_cmdAddImage_Click
' End If
Set Picture1.Picture = LoadPicture(gsFileName)
Set rsImage = objDB.OpenRecordset("Images", dbOpenDynaset) <------- Error pointing to this line
nHandle = FreeFile
Open gsFileName For Binary Access Read As nHandle
lSize = LOF(nHandle)
If nHandle = 0 Then
Close nHandle
End If
lChunks = lSize \ conChunkSize
nFragmentOffset = lSize Mod conChunkSize
rsImage.AddNew
rsImage("Description") = gsFileName
rsImage("MyKey") = lKey
ReDim Chunk(nFragmentOffset)
Get nHandle, , Chunk()
rsImage("A_Image").AppendChunk Chunk()
ReDim Chunk(conChunkSize)
lOffset = nFragmentOffset
For i = 1 To lChunks
Get nHandle, , Chunk()
rsImage("A_Image").AppendChunk Chunk()
lOffset = lOffset + conChunkSize
txtByteCount = lOffset
DoEvents
Next
rsImage.Update
End If
' End If
Exit_cmdAddImage_Click:
Exit Sub
cmdAddImage_Click_Error:
#If gnDebug Then
Stop
Resume
#End If
HandleError "cmdAddImage_Click", Err.Description, Err.Number, gErrFormName
Resume Exit_cmdAddImage_Click
End Sub
Could any one explain me on what could be the solution for this.
Below code gives me a runtime error 91 Object variable or with block variable not set.
Private Sub cmdAddImage_Click()
Dim objDB As Database
Dim rsImage As New adodb.Recordset
Dim lOffset As Long
Dim lSize As Long
Dim sPath As String
Dim nHandle As Integer
Dim lSubChunks As Long
Dim Chunk() As Byte
Dim nFragmentOffset As Integer
Dim i As Integer
Dim lChunks As Long
Dim lKey As Long
Dim sSQL As String
'On Error GoTo cmdAddImage_Click_Error
frmFileDialog.Show vbModal
If gsFileName <> "" Then
'lKey = InputBox("Please enter a Number (1..n) as a key to the image")
'i f lKey > 0 Then
'check if unique Key
' sSQL = "select * from images"
' sSQL = sSQL & " where myKey=" & lKey
' Set rsImage = objDB.OpenRecordset(sSQL, dbOpenDynaset)
' If Not rsImage.EOF Then
' MsgBox "Key is already in use"
' GoTo Exit_cmdAddImage_Click
' End If
Set Picture1.Picture = LoadPicture(gsFileName)
Set rsImage = objDB.OpenRecordset("Images", dbOpenDynaset) <------- Error pointing to this line
nHandle = FreeFile
Open gsFileName For Binary Access Read As nHandle
lSize = LOF(nHandle)
If nHandle = 0 Then
Close nHandle
End If
lChunks = lSize \ conChunkSize
nFragmentOffset = lSize Mod conChunkSize
rsImage.AddNew
rsImage("Description") = gsFileName
rsImage("MyKey") = lKey
ReDim Chunk(nFragmentOffset)
Get nHandle, , Chunk()
rsImage("A_Image").AppendChunk Chunk()
ReDim Chunk(conChunkSize)
lOffset = nFragmentOffset
For i = 1 To lChunks
Get nHandle, , Chunk()
rsImage("A_Image").AppendChunk Chunk()
lOffset = lOffset + conChunkSize
txtByteCount = lOffset
DoEvents
Next
rsImage.Update
End If
' End If
Exit_cmdAddImage_Click:
Exit Sub
cmdAddImage_Click_Error:
#If gnDebug Then
Stop
Resume
#End If
HandleError "cmdAddImage_Click", Err.Description, Err.Number, gErrFormName
Resume Exit_cmdAddImage_Click
End Sub
Could any one explain me on what could be the solution for this.