(sorry if the post is repeated twice- I got an error on the last post)
Hi macroapa:
You might have run into the linking issue that took me quite a long time to
figure out. I have a program that links up to a table located in an external
mdb container. The code that Doug posted is correct, but what you have to do
is to link TWICE to the mdb, once when you open the template and then when
you open the new doc file. So go to your VB editor pane and:
1) Go to YourProjectName-> Microsoft Word Objects-> ThisDocument and place
the following code-
Option Explicit
Private Sub Document_New()
On Error Resume Next
Dim accessword As AccessObject
'Word.Application
Dim Accesswasnotrunning As Boolean ' Flag for final release.
Dim wdWindowStateMaximize As Long
wdWindowStateMaximize = 0
On Error Resume Next
conDBpath2 = "J:\PrintCount.mdb"
Set accessword = GetObject("J:\PrintCount.mdb", "Access.Application")
accessword.Application.Visible = True
If Err.Number <> 0 Then 'test to see if an error occurred
Set accessword = CreateObject("Access.Application")
End If
If Accesswasnotrunning = True Then
accessword.Application.Quit
End If
With accessword
.WindowState = wdWindowStateMinimize
End With
Set accessword = Nothing
On Error GoTo ErrorHandler
Load frmSplashscreen
frmSplashscreen.Show
ErrorHandlerEXit:
Exit Sub
ErrorHandler:
MsgBox "Error No: " & Err.Number & "; Description: " & Err.Description
Resume ErrorHandlerEXit
End Sub
2) In your first popup form, place the following code-
Private Sub UserForm_Initialize()
On Error Resume Next
Application.DisplayAlerts = wdAlertsNone
Dim accessword As Object
Dim Accesswasnotrunning As Boolean ' Flag for final release.
Dim wdWindowStateMaximize As Long
wdWindowStateMaximize = 0
Set accessword = GetObject(, "Access.Application")
If Err.Number <> 0 Then 'test to see if an error occurred
Set accessword = CreateObject("Access.Application")
End If
Set accessword = GetObject("J:\PrintCount.mdb", "Access.Application")
If Err.Number <> 0 Then Accesswasnotrunning = True
Set accessword = CreateObject("J:\PrintCount.mdb",
"Access.Application")
If Accesswasnotrunning = True Then
accessword.Application.Quit
End If
accessword.Application.Visible = False
If Err.Number <> 0 Then 'test to see if an error occurred
Set accessword = CreateObject("Access.Application")
End If
With accessword
End With
Set accessword = Nothing
Proc_Exit:
Exit Sub
Proc_Error:
Call EMRError("WORD EMR Project.dot/" & Me.Name & ":
CommandButton11_Click()", Err.Number, Err.Source, Err.Description)
Resume Proc_Exit
End Sub
So, if you login twice, it'll work.
Regards,
Al