Solved

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

Posted on 2014-03-20
9
544 Views
Last Modified: 2014-03-27
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

0
Comment
Question by:iainmacleod
[X]
Welcome to Experts Exchange

Add your voice to the tech community where 5M+ people just like you are talking about what matters.

  • Help others & share knowledge
  • Earn cash & points
  • Learn & ask questions
  • 5
  • 4
9 Comments
 
LVL 28

Expert Comment

by:omgang
ID: 39943094
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
 

Author Comment

by:iainmacleod
ID: 39944722
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
 
LVL 28

Expert Comment

by:omgang
ID: 39945324
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
Technology Partners: We Want Your Opinion!

We value your feedback.

Take our survey and automatically be enter to win anyone of the following:
Yeti Cooler, Amazon eGift Card, and Movie eGift Card!

 

Author Comment

by:iainmacleod
ID: 39945341
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
 
LVL 28

Expert Comment

by:omgang
ID: 39945361
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
 

Author Comment

by:iainmacleod
ID: 39945372
Data type in table is OLE Object
I get error 438 with the code you supplied. Errors on the debug line
0
 
LVL 28

Expert Comment

by:omgang
ID: 39945468
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
 
LVL 28

Accepted Solution

by:
omgang earned 500 total points
ID: 39945517
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
 

Author Closing Comment

by:iainmacleod
ID: 39958322
Hello again, sorry I have been away for a few days.
This saves the image perfectly.
Many thanks
0

Featured Post

Instantly Create Instructional Tutorials

Contextual Guidance at the moment of need helps your employees adopt to new software or processes instantly. Boost knowledge retention and employee engagement step-by-step with one easy solution.

Question has a verified solution.

If you are experiencing a similar issue, please ask a related question

Phishing attempts can come in all forms, shapes and sizes. No matter how familiar you think you are with them, always remember to take extra precaution when opening an email with attachments or links.
Access developers frequently have requirements to interact with Excel (import from or output to) in their applications.  You might be able to accomplish this with the TransferSpreadsheet and OutputTo methods, but in this series of articles I will di…
Show developers how to use a criteria form to limit the data that appears on an Access report. It is a common requirement that users can specify the criteria for a report at runtime. The easiest way to accomplish this is using a criteria form that a…
Basics of query design. Shows you how to construct a simple query by adding tables, perform joins, defining output columns, perform sorting, and apply criteria.

726 members asked questions and received personalized solutions in the past 7 days.

Join the community of 500,000 technology professionals and ask your questions.

Join & Ask a Question