Question Error prompt....

zozew

Registered User.
Local time
Tomorrow, 01:05
Joined
Nov 18, 2010
Messages
199
Code:
Run-TIme error '3021'
<Unknown error/message> HRESULT : &H800A0BCD
I get that on the red code when i try to run this:

Code:
If Me.Photo.AttachmentCount <> 0 Then
     Dim db As DAO.Database
     Dim rsParent As DAO.Recordset2
     Dim rsChild As DAO.Recordset2
     Dim strFile As String
     Set db = CurrentDb
     Set rsParent = Me.Recordset
     rsParent.OpenRecordset
     [B][COLOR=Red]Set rsChild = rsParent.Fields("Photo").Value[/COLOR][/B]
     rsChild.OpenRecordset
    'File path to temp jpg file
    strFile = CurrentProject.Path & "\Templates\tempProfile.jpg"
    'Delete file if it exists
    If Dir(strFile) <> "" Then
       Kill strFile
    End If 
    ' then do your save
    rsChild.Fields("FileData").SaveToFile (strFile)
    Set rsChild = Nothing
    Set rsParent = Nothing
End If
Got most of the code from some forum...i think from here actually...

I only get that error if i replace an old image from the attachment, do a refresh. and then run the code "check if file exists on local drive then kill and replace"

If i replace an image in the record move to another record and then back to the old record and run the code i dont get the error prompt.....any ideas??
 
Re: Error promt....

:edit:

Re-reading your post, my reply was useless.

I misread the problem. ;)
 
What is actually IN the Photo field and are there any nulls there in any record? You are attempting to assign something in the photo field AS a recordset. And I am wondering if you really have a recordset stored in there. You can't assign something as a recordset, except another recordset (like a recordset clone from a form, etc.). You have to open a recordset.
 
Last edited:
Re: Error promt....

well...you are probably right boblarson. When i found the code snippet i was searching on how to overwrite a file that existed on your local drive so i could save my own from the attachment field. I just copied the code as "it" seemed to work and my knowledge on Access's use of recordset's in different places aren't that good to break it if it works. But as i explained earlier it doesn't in a very particular situation. So probably the recordset and DB and most of the first part isn't needed to get the fileData written to the local drive.

Ill change that right away and test it. But I fear the problem might still be there because as i googled it a little, the error refers to an empty record field if im not totally off. And yes sometimes the attachment field will be empty thats why i check the AttachmentCount before i try and save the file. But the error pops up when i change the attachment image do a refresh (the image displayed isnt the new one until i refresh) and try to run the code...but if i go back and forth to another record and run the code, it works fine...so im a bit confused...

Anyway ill start with cleaning up the unnecessary code and get back...

thx
 
Im not really sure but i changed to the code below and it works as before,

I get almost the same error '3021' but without the '<Unknown error/message> HRESULT : &H800A0BCD'

Is there another way of getting the fildData written to a file from the attacment field?? Without instantiating the Recordset?

Code:
If Me.Photo.AttachmentCount <> 0 Then
    Dim strFile As String
    'File path to temp jpg file
    strFile = CurrentProject.Path & "\Templates\tempProfile.jpg"
    'Delete file if it exists
    If Dir(strFile) <> "" Then
        Kill strFile
    End If
    '  Instantiate the parent recordset.
    Set rsInmate = Me.Recordset
    ' Instantiate the child recordset.
    Set rsPhoto = rsInmate.Fields("Photo").Value
    '  Save current attachment to disk in the "My Documents" folder.
    rsPhoto.Fields("FileData").SaveToFile strFile
End If
 
I don't use attachment fields and it is likely I won't do so. I think they are more trouble than they are worth and take up too much space in the database storing files in the database rather than just links to the files.

But I came across this (which you should be able to look at the SaveAttachments part and fit it to your needs).
 
Yeah i am with you on that point, but for simplicity reasons and if you knew who will administer this DB when im done, you'd advice me to keep everything in one file...

Thx for the link ill read it and adapt :)
 

Users who are viewing this thread

Back
Top Bottom