Unbound OLE object in report update

Hi Experts,

I have i report where i link to a word file through a OLE object. But i would like to change the link to another file  through VBA code. Can someone give an example how to do that?
Who is Participating?
danishaniConnect With a Mentor Commented:
You can use a Function like this below, found in this thread:

Public Function DisplayDoc(ctlDocControl As Control, strDocPath As Variant) As String

On Error GoTo Err_DisplayDoc

Dim strResult As String
Dim strDatabasePath As String
Dim intSlashLocation As Integer
Dim strImagePath

With ctlDocControl
 .Visible = True
 .Enabled = True
 .Locked = False
 ' Specify what kind of object can appear in the field.
 .OLETypeAllowed = acOLELinked
 ' Class statement--optional for Excel worksheet.
 .Class = "Microsoft Word Document"
 .SourceDoc = strDocPath
 .Action = acOLECreateLink
 ' Optional size adjustment.
 .SizeMode = acOLESizeZoom

strResult = "Document found and displayed."

End With

DisplayDoc = strResult
Exit Function

 Select Case Err.Number
   Case 2101       ' Can't find the picture.
 ctlDocControl.Visible = False
   strResult = "Can't find document."
 Resume Exit_DisplayDoc:
      Case 2455
        Resume Next
      Case Else       ' Some other error.
        MsgBox Err.Number & " " & Err.Description
        strResult = "An error occurred displaying document."
      Resume Exit_DisplayDoc:
  End Select
 End Function

Open in new window

Then in you can do something like :
Dim strWordDoc As String  
Dim ctl As Access.Control  
' or use the Common dialog to selct the new doc
strWordDoc = "C:\YourPathName\YourFileName.docx"
Set ctl = Me.ctlOleDoc  'chang the OLE object nam accordingly
DisplayDoc ctl, strWordDoc

Open in new window

Hope this helps,
DCRAPACCESSAuthor Commented:
Just what i was looking for.
Question has a verified solution.

Are you are experiencing a similar issue? Get a personalized answer when you ask a related question.

Have a better answer? Share it in a comment.

All Courses

From novice to tech pro — start learning today.