Still celebrating National IT Professionals Day with 3 months of free Premium Membership. Use Code ITDAY17

x
?
Solved

Read Write an OLE object to Access 97

Posted on 1998-08-04
5
Medium Priority
?
211 Views
Last Modified: 2012-06-27
i have an Access 97 table with an OLE object (a word 97 doc) in one of the fields.  I want to read that field into an OLE object on my form.  I know how to do it using a data control but I dont want to use data controls.
how do i set my ole object  (OLEWord) to display the data in my recordset and how do i write it back
after I have made changes to it?

eg.
set RS = dbtemp.openrecordset("mydatabase", dbOpenDynaset)
OLEWord= ????  rs.fields("Myfieldname")
...make changes...
rs.fields("Myfieldname") = OLEWord

i know this last part is wrong, but that the idea of what i need to do.
0
Comment
Question by:LewisB
[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
  • 2
  • 2
5 Comments
 
LVL 6

Expert Comment

by:clifABB
ID: 1467860
I've never done this before, so I'm not sure it will work.
But, as an idea, when you assign an object to a variable, you need to use the Set keyword.  This might work:
Set rs.fields("Myfieldname") = OLEWord

If it does, let me know and I'll repost as an answer.
0
 

Author Comment

by:LewisB
ID: 1467861
set rs.fields("MyFieldName") = OLEWord gives an  "invalid use of property" error
0
 
LVL 6

Expert Comment

by:clifABB
ID: 1467862
Sorry, it was just a thought.
0
 

Author Comment

by:LewisB
ID: 1467863
Adjusted points to 200
0
 
LVL 2

Accepted Solution

by:
mtoft earned 400 total points
ID: 1467864
This solution uses the OLE Controls method "SaveToFile"  and "ReadFromFile".


If you have any trouble, please let me know...

/Mtoft

-------------------------------------------------



Private mDB As Database

Private Const M_DATABASE = "D:\Privat\Experts Exchange Answers\Load & Save OLE\DATA.MDB"
Private Const M_TEMPFILE = "D:\Privat\Experts Exchange Answers\Load & Save OLE\TEMPFILE.DAT"

Private Sub Form_Load()
    ' Open database
    Set mDB = DBEngine.Workspaces(0).OpenDatabase(M_DATABASE)
End Sub

' Simple call the insertobj dialog, to give us some data to work with
Private Sub cmdInsertOle_Click()
    OLE1.InsertObjDlg
End Sub

' Load the first record in our table, and display it in the OLE control
Private Sub cmdLoadFromDB_Click()
    Dim rsData As DAO.Recordset
   
    ' Open the recordset
    Set rsData = mDB.OpenRecordset("SELECT * FROM OLEData;", dbOpenSnapshot)
   
    If rsData.EOF Then
        MsgBox "No oleobjects in database"
    Else
        Dim sOleData As String
        ' Get the data chunk from the recordset
        sOleData = rsData.Fields("OLEData").GetChunk(0, rsData.Fields("OLEData").FieldSize)
       
        ' Get a handle to a free temporary file
        Dim lHandle As Long
        lHandle = FreeFile()
        ' If the oledata file exists, delete it
        If Dir(M_TEMPFILE) <> "" Then Kill M_TEMPFILE
        ' The ole string is saved to a temporary file
        Open M_TEMPFILE For Binary As #lHandle
        ' Put the data
        Put #lHandle, , sOleData
        Close #lHandle
       
        ' Open the temporary file, and give it to the ole object
        lHandle = FreeFile()
        Open M_TEMPFILE For Binary As #lHandle
        ' OLE Reads the file
        OLE1.ReadFromFile lHandle
   
        ' Close the temp file handle
        Close #lHandle

        ' Delete the temp file
        Kill M_TEMPFILE
    End If
   
    ' Clean up the recordset
    rsData.Close
    Set rsData = Nothing
End Sub

' Save our OLE control's data in the first record of our table
Private Sub cmdSaveToDB_Click()
    On Error GoTo ERR_Save
    Dim rsData As DAO.Recordset
   
    ' Kill the temporary file, if it exists
    If Dir(M_TEMPFILE) <> "" Then Kill M_TEMPFILE
   
    ' Get a handle to a temporary file
    Dim lHandle As Long
    lHandle = FreeFile()
    ' The ole string is saved to a temporary file
    Open M_TEMPFILE For Binary As #lHandle
    ' OLE Reads the file
    OLE1.SaveToFile lHandle
    ' Close file
    Close #lHandle
       
    ' Read the temp file into a string variable
    Dim sData As String
    sData = Space(FileLen(M_TEMPFILE))
   
    ' Open new file handle
    lHandle = FreeFile()
    Open M_TEMPFILE For Binary As #lHandle
   
    ' Get data into a temp variable
    Get #lHandle, , sData
    ' Close handle to the temp file
    Close #lHandle
   
    ' We delete everything from the table, to make room for
    ' the new ole blob
    mDB.Execute "DELETE * From OLEData;", dbFailOnError
   
    ' Open the table, no transactions or failsafing in this example
    Set rsData = mDB.OpenRecordset("OLEData", dbOpenTable)
    rsData.AddNew
    rsData("OLEData").AppendChunk sData
    rsData.Update

    ' Delete the temp file
    Kill M_TEMPFILE
   
    ' Clean up the recordset
    rsData.Close
    Set rsData = Nothing
    Exit Sub
ERR_Save:
    MsgBox Err.Description, vbCritical
    Exit Sub
End Sub

0

Featured Post

Free Tool: ZipGrep

ZipGrep is a utility that can list and search zip (.war, .ear, .jar, etc) archives for text patterns, without the need to extract the archive's contents.

One of a set of tools we're offering as a way to say thank you for being a part of the community.

Question has a verified solution.

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

There are many ways to remove duplicate entries in an SQL or Access database. Most make you temporarily insert an ID field, make a temp table and copy data back and forth, and/or are slow. Here is an easy way in VB6 using ADO to remove duplicate row…
When trying to find the cause of a problem in VBA or VB6 it's often valuable to know what procedures were executed prior to the error. You can use the Call Stack for that but it is often inadequate because it may show procedures you aren't intereste…
Get people started with the utilization of class modules. Class modules can be a powerful tool in Microsoft Access. They allow you to create self-contained objects that encapsulate functionality. They can easily hide the complexity of a process from…
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…
Suggested Courses

715 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