Store user defined data in OLE field?

J

Jeff Polack

I'm trying to store data associated with an object that is created as a
result of a class module I've built. I thought I read somewhere that you
could do so in a table with a field that has it's data type set to OLE. Is
such a thing possible or did I just dream about such a thing?

Here's the code that fails when it gets to line that attempts to add the
clsClient data (Runtime error 438 - Object doesn't support this property or
method):

Public Sub LoadClient(strClientID As String, strPeriodBegin As String,
strPeriodEnd As String)


Dim rs As DAO.Recordset

Dim clsData As New ClientMktShare

Set rs = CurrentDb.OpenRecordset("SELECT * FROM tblTest;", dbOpenDynaset)

clsData.ClientID = strClientID
clsData.Period = strPeriodBegin
clsData.PeriodEnd = strPeriodEnd


With rs
.AddNew
!ID = strClientID
!Data = clsData <--------------- Runtime error occurs here
.Update
End With

Set rs = Nothing

End Sub

TIA
 
S

Stuart McCall

Jeff Polack said:
I'm trying to store data associated with an object that is created as a
result of a class module I've built. I thought I read somewhere that you
could do so in a table with a field that has it's data type set to OLE.
Is
such a thing possible or did I just dream about such a thing?

Here's the code that fails when it gets to line that attempts to add the
clsClient data (Runtime error 438 - Object doesn't support this property
or
method):

Public Sub LoadClient(strClientID As String, strPeriodBegin As String,
strPeriodEnd As String)


Dim rs As DAO.Recordset

Dim clsData As New ClientMktShare

Set rs = CurrentDb.OpenRecordset("SELECT * FROM tblTest;", dbOpenDynaset)

clsData.ClientID = strClientID
clsData.Period = strPeriodBegin
clsData.PeriodEnd = strPeriodEnd


With rs
.AddNew
!ID = strClientID
!Data = clsData <--------------- Runtime error occurs here
.Update
End With

Set rs = Nothing

End Sub

TIA

Even if you could get this to work, I doubt you'd find a way to persuade
Access to make use of a binary image of an object.

Why not create a table with the fields ClientID, Period and PeriodEnd, then
update that?
 
J

Jeff Polack

Thanks for taking the time to reply. The premise of the question is the the
OLE type would take any kind of binary data, not just images.

The posted example is just a basic class object to test the theory. The
actual data would be more complex and be used to store the results of many
complex and time consuming calculations. The fallback position is to create
a table with all of the data elements.

Again, thanks for your time.
 
S

Stuart McCall

Jeff Polack said:
Thanks for taking the time to reply. The premise of the question is the
the
OLE type would take any kind of binary data, not just images.

The posted example is just a basic class object to test the theory. The
actual data would be more complex and be used to store the results of many
complex and time consuming calculations. The fallback position is to
create
a table with all of the data elements.

I have no idea how to store a class object in an OLE field. I've only ever
done this with byte arrays and strings.

Presumably you would have these calc results in some kind of variable? If
not a byte array or a string, I think you would have to use the API function
RtlMoveMemory to copy your bytes into a correctly sized buffer using one of
those two types, then store that in your OLE field. Getting the data back
out of the field and into a usable form will likely be more complex.

IOW there is no built-in method (AFAIK). You'll have to hack something
together as above. Not for the faint-hearted.
It's probably doable but maybe not worth the time/effort..
 
J

Jeff Polack

Kinda figured it would take something as involved as that. On to Plan B!

Thanks for the response.
 

Ask a Question

Want to reply to this thread or ask your own question?

You'll need to choose a username for the site, which only take a couple of moments. After that, you can post your question and our members will help you out.

Ask a Question

Top