Tek-Tips is the largest IT community on the Internet today!

Members share and learn making Tek-Tips Forums the best source of peer-reviewed technical information on the Internet!

  • Congratulations strongm on being selected by the Tek-Tips community for having the most helpful posts in the forums last week. Way to Go!

Open a Word Document from an Access Form

Status
Not open for further replies.

wandan

Technical User
Dec 16, 2001
101
US
I would like to be able to open a word document using a command button on an access form. Is there any easy way to do this??
 
I have done it using a form with a description field, a hyperlink field, an edit button and a open document button.

the edit button has the following code:

Code:
Private Sub Update_Click()
On Error GoTo Update_Click_Err

Me!URL.Enabled = True

If Me!URL <> &quot;&quot; Then
   Me!URL = Null
End If
Me!URL.SetFocus
RunCommand acCmdEditHyperlink
Me!Update.SetFocus
Me!URL.Enabled = False
Exit Sub

Update_Click_Err:
If Err.Number = 432 Then
    MsgBox &quot;Unable to locate file: Use the find file button to locate the file and refresh the link&quot;, vbOKOnly, &quot;File Find Error!&quot;
End If
End Sub

and the open link does this:

Code:
Private Sub Open_Click()
On Error GoTo Open_Click_Err

Me!URL.Hyperlink.Follow

Exit Sub

Open_Click_Err:

If Err.Number = 432 Then
    MsgBox &quot;Unable to locate file: Use the find file button to locate the file and refresh the link&quot;, vbOKOnly, &quot;File Find Error!&quot;
Else
    MsgBox &quot;Error No: &quot; & Err.Number & &quot;; &quot; & Err.Description
End If
End Sub

This is pretty crude, and irritatingly always opens Words 'address' bar, but it was quick to set up, and has the bonus of allowing you to link to almost any file - Office files, text, images, whatever - they will open in thier default viewers.

I'll flag this message to see if anyone has better suggestions!
 
At the OnClick event of the button

Private Sub OnClick_Button1()

Dim oApp As Word.Application
Dim oDoc As Word.Document

Set db = CurrentDb

Set oApp = CreateObject(&quot;Word.Application&quot;)
Set oDoc = oApp.Documents.Add(&quot;C:\Your_Word_App.doc&quot;)
oApp.Visible = True
.
.
do whatever automation you like

End sub

Remember to set a reference to the Word object library
 
Status
Not open for further replies.

Part and Inventory Search

Sponsor

Back
Top