OLE Object does not update

NascarBaritone

Registered User.
Local time
Today, 01:23
Joined
Sep 23, 2008
Messages
75
I currently have a bound object frame (named: OLEBound17) in my report that has the control source of an OLE object field (named: OBA) in my table (named: Reps). The OLE object field in the table has Word documents that are linked to a Word document (1 per record) that are different for each record in my database. When I run the report from my form, the Word document shows up fine in the report (at first). However, if I open the Word document in Word, make changes, and save it with the exact same name, nothing shows up in the report the next time it is run. If I go in to the table, delete the file, and Insert Object... after making the changes it shows up fine.

I was under the impression that a linked OLE field would automatically update itself if changes were made to the linked document. I really don't want to have to go into the table and delete/insert every time I make a change to the file. Also, I don't think this has anything to do with it, but I do have my database split (FE and BE).

Any suggestions?
 
Hi NascarBaritone - did you ever figure this one out?
I'm having a big problem with my linked ole object - I'm trying to link (in a subform) a dynamically generated ole unbound object source. It's a pdf file name stored in a folder and I generate the source name dynamically. I store it in a query which is the source of the form.

Then I added the form as a subform in my access report. It displays great the first time. But if I run the report again, it doesn't update the ole object. I'm pulling my hair out trying to figure out why.

In case any of you can help me please let me know. I'm going crazy!

Here is my form, frmLinkFix...the record source is a query that has the pathname in the main and only field (Imagepath). I also want to display a blank value or hopefully just nothing if there is no document named ST123456.pdf - but that's another issue altogether. I have the picture type as Linked, in Size Mode Clip.
Private Sub Form_Current()
CallDisplayImage
End Sub

Private Sub CallDisplayImage()
On Error GoTo Form_Error
Dim bPath As String
bPath = "BlankTechRpt.pdf"
Dim sPath As String
sPath = Me![Imagepath]
With Me![OLE1]
.Locked = False
.Enabled = True
'OLE1.Class = "Paint.Picture" ' Set class name.
.Class = "AcroExch.Document.8"
' Specify type of object.
.OLETypeAllowed = acOLEEither 'not acOLEEmbedded, acOLELink
' Specify source file.
.SourceDoc = sPath
' Specify data to create link to.
.SourceItem = ""
' Create linked object.
.Action = acOLECreateLink 'not acOLECreateLink
' Adjust control size.
.SizeMode = acOLESizeZoom
End With

Form_Exit:
Exit Sub

Form_Error:
'MsgBox "Error: " & Error & " (" & Err & ")"
Me![OLE1].Action = acOLEDelete
'Me![OLE1].SourceDoc = ""
Me![OLE1].SourceDoc = bPath
Me![OLE1].Action = acOLECreateLink
Me![OLE1].SizeMode = acOLESizeZoom
' Resume Next

End Sub
Ok this works great but then I insert this mofo in my report and it wont update, unless I totally close access and reopen it. Sometimes that works.

On my report, under the property sheet, the subform's name is frmLinkFix (my form) and the source object is Form.frmLinkFix. On the detail properties, It's an Unbound Object Frame, OLE type is linked, and the Source Doc is populated with the path to the pdf file name. That all looks good, but what actually displays in the report preview is the old file name, not the new one.

Is there something I missed to make the value displayed actually match the source of the OLE object?
 
Last edited:
Hi Holz,

I am having the same problem. I searched several forums, but I can not find a solution to this problem. Did you find a solution? Is so I would really appreciate any help. Thanks.
 
Did anyone ever solve this? I am having the same problem.
 
I was able to solve this by modifying some VBA-code I found. In principle you have a vba-code, which remove the ole-object and then insert it again. I do this in a database each day. By doing this your are forcing access to update the ole-object.

I can not remember who made the original code, which I modified. But all the credits to that person. I have inserted the VBA-codes I use. I hope you can modify these to your needs.

Regards,

Torben

Option Compare Database
Option Explicit

Function GetLinkedPath(objOLE As Variant) As Variant
Dim strChunk As String
Dim pathStart As Long
Dim pathEnd As Long
Dim path As String
If Not IsNull(objOLE) Then
'Convert string to Unicode.
strChunk = StrConv(objOLE, vbUnicode)
pathStart = InStr(1, strChunk, ":\", 1) - 1

'If mapped drive path is not found, try UNC path.
If pathStart <= 0 Then pathStart = InStr(1, strChunk, "\\", 1)

'If either drive letter path or UNC path is found, determine
'the length of the path by searching for the first null
'character Chr(0) after the path was found.
If pathStart > 0 Then
pathEnd = InStr(pathStart, strChunk, Chr(0), 1)
path = Mid(strChunk, pathStart, pathEnd - pathStart)
GetLinkedPath = path
Exit Function
End If
Else
GetLinkedPath = Null
End If
End Function


Option Compare Database
Option Explicit

Sub SetOLEPath(objform As Form, OLEName As String, NewPath As String)
On Error GoTo ErrSetOLEPath

Dim objOLE As Variant
Dim tmpPath As String
Dim tmpClass As String
Dim iCount As Integer
Dim oldPath As String
Dim rs As Recordset

oldPath = ""
Set rs = objform.Recordset
rs.MoveFirst
Do
objOLE = objform(OLEName)

'Get the current path for the linked OLE object.
oldPath = GetLinkedPath(objOLE)

'Determine the file name from the current path.
If oldPath <> "" Then
iCount = 0
tmpPath = oldPath
Do
iCount = InStr(tmpPath, "\")
If iCount > 0 Then
tmpPath = Mid(tmpPath, iCount + 1)
End If
Loop Until iCount = 0
End If

'Set the new path and file name for the OLE object.
With objform(OLEName)

'OLE object must be enabled and unlocked for modification to take place.
.enabled = True
.Locked = False
tmpClass = .Class

'Remove the current object; otherwise, the object cannot be changed.
objform.Recordset.Edit
objform.Recordset(objform(OLEName).ControlSource) = ""
objform.Recordset.Update
.OLETypeAllowed = acOLELinked
.Class = tmpClass

'Put in the new path and file name.
.SourceDoc = oldPath
'.SourceDoc = NewPath & IIf(Right(NewPath, 1) = "\", "", "\") & tmpPath

'Create the actual link
.Action = acOLECreateLink
.SizeMode = acOLESizeZoom
End With

'Move to the next record.
rs.MoveNext
Loop Until rs.EOF
Exit Sub

ErrSetOLEPath:
MsgBox Error
MsgBox Err
Resume Next
End Sub


Option Compare Database
Option Explicit

Function UpdateOLE1(FormName As String, OLEName As String, NewPath As String)

'?UpdateOLE("frmFormular", "MetaStock1", "<New path to linked files>")
'.FilterOn = True
' DoCmd.ApplyFilter , "[TMS_DATE] >= " & DateValue(!txtWkStart) & "

Dim myForm As Form
Dim oldPath As String
Dim rtn As Variant

'Open the form if it is not already open.
DoCmd.OpenForm FormName, acNormal, , , acFormEdit
DoCmd.ApplyFilter , "(MetaStock1<>'') "


'DoCmd.ApplyFilter ,"(status_probleem = 'open') "

'Bring the form to the front if it is currently behind other objects. FEJL I SET MYFORM
DoCmd.SelectObject acForm, FormName
Set myForm = Forms(FormName)

'Call the subroutine to make changes to the OLE object in the form.
SetOLEPath myForm, OLEName, NewPath
DoCmd.Close acForm, FormName

End Function
 
Found a simple refresh workaround for a bound html ole-object.

I have a web page embedded in a form. After modifying the underlying web page, I just unlinked and relinked the source file to refresh. e.g.

Dim sCtrlSource
sCtrlSource =
Me.WebBrowser1.ControlSource
Me.WebBrowser1.ControlSource = ""
Me.WebBrowser1.ControlSource =
sCtrlSource

It may also work for other ole-objects.

 

Users who are viewing this thread

Back
Top Bottom