Solved

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

Posted on 2014-03-20
9
525 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
  • 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
 

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
Free Trending Threat Insights Every Day

Enhance your security with threat intelligence from the web. Get trending threat insights on hackers, exploits, and suspicious IP addresses delivered to your inbox with our free Cyber Daily.

 
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

Find Ransomware Secrets With All-Source Analysis

Ransomware has become a major concern for organizations; its prevalence has grown due to past successes achieved by threat actors. While each ransomware variant is different, we’ve seen some common tactics and trends used among the authors of the malware.

Join & Write a Comment

Suggested Solutions

This article is a continuation or rather an extension from Cascading Combos (http://www.experts-exchange.com/A_5949.html) and builds on examples developed in detail there. It should be understandable alone, but I recommend reading the previous artic…
In the article entitled Working with Objects – Part 1 (http://www.experts-exchange.com/Microsoft/Development/MS_Access/A_4942-Working-with-Objects-Part-1.html), you learned the basics of working with objects, properties, methods, and events. In Work…
Familiarize people with the process of utilizing SQL Server stored procedures from within Microsoft Access. Microsoft Access is a very powerful client/server development tool. One of the SQL Server objects that you can interact with from within Micr…
In Microsoft Access, learn how to use Dlookup and other domain aggregate functions and one method of specifying a string value within a string. Specify the first argument, which is the expression to be returned: Specify the second argument, which …

747 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

Need Help in Real-Time?

Connect with top rated Experts

12 Experts available now in Live!

Get 1:1 Help Now