save objects to an Access database using ADO 
Author Message
 save objects to an Access database using ADO

I'm trying to save an object to an Access database using ADO in VB code.
I've indicated Ole Object as the field type in Access.  The problem that I
have is saving the object.

RS!Field = MyObject doesn't do the trick, nor does Set RS!Field = MyObject.

Anyone have a clue?

Thanks, Alex



Sun, 22 Aug 2004 09:38:47 GMT  
 save objects to an Access database using ADO
Alex.
 AFAIK you can not create objects that way, Best way is using adox ( ADO
Extentions for DDL and security).

--
hth
Hirantha
Please reply only to the newsgroups.

*** Sent via Developersdex http://www.developersdex.com ***
Don't just participate in USENET...get rewarded for it!



Sun, 22 Aug 2004 09:52:16 GMT  
 save objects to an Access database using ADO
Alex,
Suggest you specify what object you are refering to.
The following extract will save an instance of an Activereport to an OLE field
in an access db.

' declaring stream object to hold Binary data
    Set .Stream = New ADODB.Stream
    .Stream.Type = adTypeBinary
    .Stream.Open
' create a temp folder if one does not exist
    Dim fso As FileSystemObject
    Set fso = New FileSystemObject
    If Not fso.FolderExists(App.Path & "\Temp") Then
    fso.CreateFolder (App.Path & "\Temp")
    End If
' save the open report to a drTemp file in the temp folder
    With Screen.ActiveForm
        If .arv.Pages.Count > 0 Then
            .arv.Pages.Save App.Path & "\Temp\drTemp.RDF"
        ElseIf Not .arv.ReportSource Is Nothing Then
            If .arv.ReportSource.Pages.Count > 0 Then
                .arv.ReportSource.Pages.Save App.Path & "\Temp\drTemp.RDF"
            End If
        End If
    End With
' load the temp file into the stream object
    .Stream.LoadFromFile App.Path & "\Temp\drTemp.RDF"
' add a new record to the recordset
    .Recordset.AddNew
' writing the data report into Field(FieldName) as binary data.
    .Recordset.Fields(sFieldDataName).Value = .Stream.Read
    .Recordset.Fields(sFieldReferenceName).Value = sStr
    .Recordset.Update
' delete the drTemp file
    fso.DeleteFile App.Path & "\Temp\drTemp.RDF"
' tidy up
    .Stream.Close
    Set .Stream = Nothing

It may help
Cheers
Dave

Quote:

> I'm trying to save an object to an Access database using ADO in VB code.
> I've indicated Ole Object as the field type in Access.  The problem that I
> have is saving the object.

> RS!Field = MyObject doesn't do the trick, nor does Set RS!Field = MyObject.

> Anyone have a clue?

> Thanks, Alex



Sun, 22 Aug 2004 18:00:48 GMT  
 save objects to an Access database using ADO
Dave,

It doesn't seem to matter what kind of object I use, since I've tried
several with the same results (err: -2147352562) Invalid number of
paramters).  The line that's failing is:
    RS!MyField = MyOject

which I've also tried as:

    RS("MyField").value = MyObject

and:

    RS("MyField").value = AnyObject.

Question: In your example which dataype are you using for the field in your
database?

Alex

Quote:

>Alex,
>Suggest you specify what object you are refering to.
>The following extract will save an instance of an Activereport to an OLE
field
>in an access db.

>' declaring stream object to hold Binary data
>    Set .Stream = New ADODB.Stream
>    .Stream.Type = adTypeBinary
>    .Stream.Open
>' create a temp folder if one does not exist
>    Dim fso As FileSystemObject
>    Set fso = New FileSystemObject
>    If Not fso.FolderExists(App.Path & "\Temp") Then
>    fso.CreateFolder (App.Path & "\Temp")
>    End If
>' save the open report to a drTemp file in the temp folder
>    With Screen.ActiveForm
>        If .arv.Pages.Count > 0 Then
>            .arv.Pages.Save App.Path & "\Temp\drTemp.RDF"
>        ElseIf Not .arv.ReportSource Is Nothing Then
>            If .arv.ReportSource.Pages.Count > 0 Then
>                .arv.ReportSource.Pages.Save App.Path & "\Temp\drTemp.RDF"
>            End If
>        End If
>    End With
>' load the temp file into the stream object
>    .Stream.LoadFromFile App.Path & "\Temp\drTemp.RDF"
>' add a new record to the recordset
>    .Recordset.AddNew
>' writing the data report into Field(FieldName) as binary data.
>    .Recordset.Fields(sFieldDataName).Value = .Stream.Read
>    .Recordset.Fields(sFieldReferenceName).Value = sStr
>    .Recordset.Update
>' delete the drTemp file
>    fso.DeleteFile App.Path & "\Temp\drTemp.RDF"
>' tidy up
>    .Stream.Close
>    Set .Stream = Nothing

>It may help
>Cheers
>Dave

>> I'm trying to save an object to an Access database using ADO in VB code.
>> I've indicated Ole Object as the field type in Access.  The problem that
I
>> have is saving the object.

>> RS!Field = MyObject doesn't do the trick, nor does Set RS!Field =
MyObject.

>> Anyone have a clue?

>> Thanks, Alex



Mon, 23 Aug 2004 01:00:40 GMT  
 save objects to an Access database using ADO

Quote:

> Dave,

> It doesn't seem to matter what kind of object I use, since I've tried
> several with the same results (err: -2147352562) Invalid number of
> paramters).  The line that's failing is:
>     RS!MyField = MyOject

> which I've also tried as:

>     RS("MyField").value = MyObject

> and:

>     RS("MyField").value = AnyObject.

> Question: In your example which dataype are you using for the field in your
> database?

The database recordset contains 3 fields.
1. Autonumber
2. ReportReference using text datatype. Used for retrieving an instance of an
object.
3. ReportData using OLE Object datatype. Used for holding the binary data of
the object.

Cheers
 Dave

- Show quoted text -

Quote:

> Alex


> >Alex,
> >Suggest you specify what object you are refering to.
> >The following extract will save an instance of an Activereport to an OLE
> field
> >in an access db.

> >' declaring stream object to hold Binary data
> >    Set .Stream = New ADODB.Stream
> >    .Stream.Type = adTypeBinary
> >    .Stream.Open
> >' create a temp folder if one does not exist
> >    Dim fso As FileSystemObject
> >    Set fso = New FileSystemObject
> >    If Not fso.FolderExists(App.Path & "\Temp") Then
> >    fso.CreateFolder (App.Path & "\Temp")
> >    End If
> >' save the open report to a drTemp file in the temp folder
> >    With Screen.ActiveForm
> >        If .arv.Pages.Count > 0 Then
> >            .arv.Pages.Save App.Path & "\Temp\drTemp.RDF"
> >        ElseIf Not .arv.ReportSource Is Nothing Then
> >            If .arv.ReportSource.Pages.Count > 0 Then
> >                .arv.ReportSource.Pages.Save App.Path & "\Temp\drTemp.RDF"
> >            End If
> >        End If
> >    End With
> >' load the temp file into the stream object
> >    .Stream.LoadFromFile App.Path & "\Temp\drTemp.RDF"
> >' add a new record to the recordset
> >    .Recordset.AddNew
> >' writing the data report into Field(FieldName) as binary data.
> >    .Recordset.Fields(sFieldDataName).Value = .Stream.Read
> >    .Recordset.Fields(sFieldReferenceName).Value = sStr
> >    .Recordset.Update
> >' delete the drTemp file
> >    fso.DeleteFile App.Path & "\Temp\drTemp.RDF"
> >' tidy up
> >    .Stream.Close
> >    Set .Stream = Nothing

> >It may help
> >Cheers
> >Dave

> >> I'm trying to save an object to an Access database using ADO in VB code.
> >> I've indicated Ole Object as the field type in Access.  The problem that
> I
> >> have is saving the object.

> >> RS!Field = MyObject doesn't do the trick, nor does Set RS!Field =
> MyObject.

> >> Anyone have a clue?

> >> Thanks, Alex



Thu, 26 Aug 2004 03:24:20 GMT  
 
 [ 5 post ] 

 Relevant Pages 

1. RTF save using ADO / COM to Access / SQL database

2. Accessing Access with database level password using ADO

3. ADO using MS Access with mdw system database for pw-access

4. Save and load picture files in database by using ADO !(SRC)

5. Saving images to a database using ADO

6. saving ado recordset to MS Access database

7. Very slow save of objects in big Access 2000 databases

8. Saving/Retrieving a Winword object in a Access database

9. Saving objects to a relational database (Access)

10. Saving OLE Object into Access Database

11. Saving OLE object from VB to Access Database binary field

12. Saving OLE Object into Access Database

 

 
Powered by phpBB® Forum Software