Run-Time error 2101 when saving a record with Ole Object

I need to be able to save a record from an unbound form. This Form contains an image.
If the form is bound the image saves. Unbound I get the error.
The field in the table is OLE and this is the code in a button on the form.
Thanks

Dim dbs As DAO.Database, grn As DAO.Recordset

Set dbs = CurrentDb
Set grn = dbs.OpenRecordset("grn", dbOpenDynaset)
If IsNull(Me.Name) Then
MsgBox ("Please complete all fields!"), vbInformation, "Incomplete"
Else
grn.AddNew
            grn!dname = Me.Name
            grn!image = Me.dimage
            grn!dcompany = Me.company
            grn!dlicenseplate = Me.vehicle
            grn!date = Me.date
            grn!grnno = Me.grnnumber
grn.Update
MsgBox ("This has been saved!"), vbInformation, "Saved"
End If
DoCmd.Close

Open in new window

iainmacleodAsked:
Who is Participating?
 
omgangConnect With a Mentor IT ManagerCommented:
I'm thinking it must be and Unbound Object Frame as a Bound Frame is bound to a field in the underlying table recordset.

Just tried this and it seems to work.  Please let me know.
I added an Unbound Object Frame to the form and have am image loaded into it.  I use the code below to save the image to a db table field with an OLE Object data type.
OM Gang


Private Sub Form_Load()
On Error GoTo Err_Form_Load


   
    Dim varData As Variant
    Dim strSQL As String
   
   
    varData = Me.OLEUnbound14.VarOleObject
    Debug.Print "UBound :  " & varData
   
    strSQL = "INSERT INTO Table2 (Image) VALUES (" & varData & ")"
    CurrentDb.Execute strSQL
     
   
Exit_Form_Load:
    Exit Sub
   
Err_Form_Load:
    MsgBox Err.Number & ", " & Err.Description, , "Error in Form Load"
    Resume Exit_Form_Load
   
End Sub
0
 
omgangIT ManagerCommented:
I recently ran into a similar situation with unbound forms.  Consider that you're referring to the form recordset column/field names with
Me.Name
Me.dimage
etc.

If the form is unbound, there is no underlying recordset thus no recordset column names.  Try referring to the form controls instead, e.g.
Me.txtName
Me.MyImageControl
etc.

OM Gang
0
 
iainmacleodAuthor Commented:
Hi,
The me.name and me.dimage are the controls on my form. The code works fine without the reference to the ole object (me.dimage).
I think it has some thing to do with specifying the type of control that me.dimage is.
0
Free Tool: Subnet Calculator

The subnet calculator helps you design networks by taking an IP address and network mask and returning information such as network, broadcast address, and host range.

One of a set of tools we're offering as a way of saying thank you for being a part of the community.

 
omgangIT ManagerCommented:
So I've done some brief testing.  I added an image control to an unbound form and can obtain the image name from
Me.dimage.Picture
Are you wanting to save just the file name or the actual image object?

OM Gang
0
 
iainmacleodAuthor Commented:
Hi, I can obtain the image ok but when i run the code to save from a command button I was getting Error 2101.
If I change that code to me.dimage.picture I get error "438" Object doesnt support this property.
Dim dbs As DAO.Database, grn As DAO.Recordset

Set dbs = CurrentDb
Set grn = dbs.OpenRecordset("grn", dbOpenDynaset)

DoCmd.SetWarnings False


If IsNull(Me.Name) Then
MsgBox ("Please complete all fields!"), vbInformation, "Incomplete"
Else
grn.AddNew
            grn!DName = Me.DName
            grn!image = Me.dimage.Picture
            grn!Dcompany = Me.company
            grn!Dlicenseplate = Me.vehicle
            grn!date = Me.date
            grn!GRNno = Me.grnnumber
            
grn.Update
MsgBox ("This has been saved!"), vbInformation, "Saved"
End If
DoCmd.Close
DoCmd.SetWarnings True

Open in new window


I am trying to save the image into a table
0
 
omgangIT ManagerCommented:
What do you get when you do this?  What is the data type for the table column/field grn!image ?

Else
Debug.Print Me.dimage.Picture

grn.AddNew
            grn!DName = Me.DName
            grn!image = Me.dimage.Picture
            grn!Dcompany = Me.company
            grn!Dlicenseplate = Me.vehicle
            grn!date = Me.date
            grn!GRNno = Me.grnnumber
           
grn.Update
0
 
iainmacleodAuthor Commented:
Data type in table is OLE Object
I get error 438 with the code you supplied. Errors on the debug line
0
 
omgangIT ManagerCommented:
The control I added to my unbound form was an Image control.  On your form it must be either a bound or unbound Object Frame?
OM Gang
0
 
iainmacleodAuthor Commented:
Hello again, sorry I have been away for a few days.
This saves the image perfectly.
Many thanks
0
Question has a verified solution.

Are you are experiencing a similar issue? Get a personalized answer when you ask a related question.

Have a better answer? Share it in a comment.

All Courses

From novice to tech pro — start learning today.