Want to win a PS4? Go Premium and enter to win our High-Tech Treats giveaway. Enter to Win

x
?
Solved

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

Posted on 2014-03-20
9
Medium Priority
?
562 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
Windows Server 2016: All you need to know

Learn about Hyper-V features that increase functionality and usability of Microsoft Windows Server 2016. Also, throughout this eBook, you’ll find some basic PowerShell examples that will help you leverage the scripts in your environments!

 

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 2000 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

Tech or Treat! - Giveaway

Submit an article about your scariest tech experience—and the solution—and you’ll be automatically entered to win one of 4 fantastic tech gadgets.

Question has a verified solution.

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

This article describes a method of delivering Word templates for use in merging Access data to Word documents, that requires no computer knowledge on the part of the recipient -- the templates are saved in table fields, and are extracted and install…
Explore the ways to Unlock VBA Project Password Excel 2010 & 2013 documents. Go through the article and perform the steps carefully to remove VBA Excel .xls file.
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 …
Access reports are powerful and flexible. Learn how to create a query and then a grouped report using the wizard. Modify the report design after the wizard is done to make it look better. There will be another video to explain how to put the final p…

598 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