Am an absolute novice using access and VBA and would appreciate an example of VB code to test for an instance of word. Am using Access 11.0 with VBA 6.04.
Many thanks in advance,
Best regards.
Printable View
Am an absolute novice using access and VBA and would appreciate an example of VB code to test for an instance of word. Am using Access 11.0 with VBA 6.04.
Many thanks in advance,
Best regards.
Welcome to the Forums.
You can test for a running instance of Word by using the GetObject function.
VB Code:
Option Explicit 'Add a reference to MS Word xx.0 Object Library Private Sub Command1_Click() Dim oApp As Word.Application Set oApp = GetObject(, "Word.Application) If TypeName(oApp) <> "Nothing" Then 'A Word instance is running Else 'No Word instances running. End If '... '... End Sub
Many thanks for the reply.
This is the code I have used and when run, I get a
Run-time error '429':
ActiveX component can't create object - at the Set oApp = GetObject (, "Word.Application") line.
VB Code:
Private Sub Image251_Click() 'Test to see if Word is running Dim oApp As Word.Application Dim Response Set oApp = GetObject (, "Word.Application") If TypeName(oApp) = "Nothing" Then 'Word is not running so load it Response = MsgBox("WORD HAS BEEN SHUT DOWN AGAIN!! - So I have loaded it for you ......", vbOKOnly) Set oApp = New Word.Application oApp.Visible = True oApp.WindowState = wdWindowStateMinimise Else 'Word is running Set oaPP = Nothing Set Response = Nothing End If
Have had a look around to see if I could solve the problem without bothering you - most suggestions seem to point to unregistered applications, missing DLL's etc.
Office 2003 (Word) has been installed for some time and has all of the latest updates so I would be surprised if that is the issue.
Thanks for taking the time.
Kind regards.
I forgot the "On Error Resume Next" statement which should go right after the "Private Sub Image251_Click()" line
All the error is saying is that Word is not running.
Don't you guys sleep?
That's cracked it - thanks again.