Hi all, I want a word doc to open when I click a button - simple.
The problem is that I have to click the button twice to get the doc to open. How do I get it to work on a single click?
Many thanks
Here's my code:
The problem is that I have to click the button twice to get the doc to open. How do I get it to work on a single click?
Many thanks
Here's my code:
Code:
Private Sub cmdInstruct_Click()
Dim appWord As Word.Application
Dim doc As Word.Document
'Avoid error 429, when Word isn't open.
On Error Resume Next
'Err.Clear
'Set appWord object variable to running instance of Word.
Set appWord = GetObject(, "Word.Application")
If Err.Number <> 0 Then
'If Word isn't open, create a new instance of Word.
Set appWord = New Word.Application
End If
If cboInstruct.Value = "Contractor's Notification" Then
Set doc = appWord.Documents.Open("[URL="file://\\mylocation\StdLetter.doc"]\\mylocation\StdLetter.doc[/URL]", , True)
With doc
.FormFields("ProjRef").Result = Me!txtProjID
.FormFields("ProjName").Result = Me!txtProjTitle
.Visible = True
.Activate
End With
Set doc = Nothing
Set appWord = Nothing
Exit Sub
errHandler:
MsgBox Err.Number & ": " & Err.Description
End If
End Sub