Display Word Document on Access Form

  • Thread starter Thread starter Todd Wilson
  • Start date Start date
T

Todd Wilson

I would like my users to be able to select a Word document from the hard
drive and display that document on a form.

My database allows users to assign maintenance procedures to a particular
piece of equipment. These procedures are stored on the hard drive in word
documents. I have no problem with the selection of the file and assigning
the file name to a field in a schedule table, but I would like the user to
have the option of displaying the file read-only on the form.

I have looked at bound and unbound objects, but do not know how to assign a
file to such an object.

Any suggestions?
Thanks,
Todd
 
You can use an Unbound Frame control and link to the document by specifying
the full path to the document file as the SourceDoc property and set the
Action property to acOLECreateLink. See clip below from the Access help
function:
This will open Word in the frame control with all the features of Word,
including menus etc.
You can use the methods and properties of the frame controls to manipulate
Word from code, for example to hide menus.
You need to read thoroughly through the help files on Frame controls, this a
topic requiring advanced programming skills.

Ragnar

You can use the SourceDoc property to specify the file to create a link to
or to embed when you create a linked object or embedded object by using the
Action property in Visual Basic.
Setting
For an embedded object, enter the full path and file name for the file you
want to use as a template and set the Action property to acOLECreateEmbed.
For a linked object, enter the full path and file name of the file to create
a link to and set the Action property to acOLECreateLink.
You can set this property in a property sheet, in a macro, or by using
Visual Basic.
Note While this property appears in the property sheet, it takes effect
only after the Action property is set in a macro or by using Visual Basic.
Remarks
You can use the SourceDoc property to specify the file to create a link to
and the control's SourceItem property to specify the data within that file.
If you want to create a link to the entire object, leave the SourceItem
property blank.
When a linked unbound object is created, the control's SourceItem property
setting is concatenated with its SourceDoc property setting. In Form view,
Datasheet view, and Print Preview, the control's SourceItem property setting
is a zero-length string (" "), and its SourceDoc property setting is the
full path to the linked file, followed by an exclamation point (!) or a
backslash (\) and the SourceItem property setting, as in the following
example:
"C:\Work\Qtr1\Revenue.xls!R1C1:R30C15"
 
Ragnar,

Thank you! What I have is a little rough yet, but it is working and it is
just what I wanted to do! Following is the code I have so far to populate
the unbound control. I'll be cleaning it up tonight - again, thank you!

Sincerely,
Todd Wilson

Private Sub cmdSelectFile_Click()
On Error GoTo Err_cmdSelectFile_Click
'Displays the Office File Open dialog to choose a PM Procedure file name
'to display on the form.

Dim fileName As String
Dim Result As Integer

With Application.FileDialog(msoFileDialogFilePicker)
.Title = "Select PM Procedure..."
.Filters.Add "All Files", "*.*"
.AllowMultiSelect = False
.InitialFileName = CurrentProject.Path & "\Procedures\"
Result = .Show
If (Result <> 0) Then
fileName = Trim(.SelectedItems.Item(1))
Me!OLEUnbound1.Class = "WordPad"
Me!OLEUnbound1.OLETypeAllowed = acOLELinked
Me!OLEUnbound1.SourceDoc = fileName
Me!OLEUnbound1.Action = acOLECreateLink
Me!OLEUnbound1.SizeMode = acOLESizeZoom
End If
End With

Exit_cmdSelectFile_Click:
Exit Sub

Err_cmdSelectFile_Click:
MsgBox Err.Description
Resume Exit_cmdSelectFile_Click

End Sub
 
Hello Todd,

Glad to help. I have gotten a lot of help from these newsgroups over the
years, and I like to give some back.

Ragnar
 
Back
Top