D
Duncan
I'm using the code at the end of this post to populate a Microsoft Word
template with data from fields in an Access 97 database. The database is
on an server running NT Server 4, with the templates on each client
machine (located at C:\Standard Letters\Templates).
I have a mixture of NT4 Workstation and XP Pro client machines.
Everything works great on the NT machines, and when logged in with
administrator privileges on the XP machines.
However, when logged on as a normal user (a member of "Domain Users"
using a roaming profile) on the XP machines, Word is started and the
relevant template is loaded, but no data is pulled across from Access.
I've had a dig around the MS KB and Google Groups but have not found any
pointers towards a solution yet. As such, I'd be grateful for any
suggestions.
Duncan McKenzie
TRC Ltd.
-----------
start paste
-----------
Private Sub cmdTPILetter_Click()
Dim objWord As Object
Dim WordWasNotRunning As Boolean ' Flag for final release.
On Error Resume Next
Set objWord = GetObject(, "Word.Application")
If Err.Number <> 0 Then WordWasNotRunning = True
Err.Clear ' Clear Err object in case error occurred.
DetectWord
On Error GoTo Err_cmdTPILetter_Click
If WordWasNotRunning Then
Set objWord = CreateObject("Word.Application")
End If
With objWord
.Visible = True
Debug.Print Me![TPInsurer]
Debug.Print "[InsurerID] = " & "'" & Me![TPInsurer] & "'"
.Documents.Add Template:="c:\Standard
Letters\Templates\TPIgenrep.dot"
.ActiveDocument.Bookmarks("PHCompName").Select
.selection.Text = (CStr(DLookup("[CompanyName]", "tblInsurers",
"[InsurerID] = " & "'" & Me![TPInsurer] & "'")))
.ActiveDocument.Bookmarks("Address").Select
.selection.Text = (CStr(DLookup("[OfficeAddress]",
"tblInsurers", "[InsurerID] = " & "'" & Me![TPInsurer] & "'")))
.ActiveDocument.Bookmarks("Location").Select
.selection.Text = (CStr(DLookup("[Location]", "tblInsurers",
"[InsurerID] = " & "'" & Me![TPInsurer] & "'")))
.ActiveDocument.Bookmarks("PostTown").Select
.selection.Text = (CStr(DLookup("[Posttown]", "tblInsurers",
"[InsurerID] = " & "'" & Me![TPInsurer] & "'")))
.ActiveDocument.Bookmarks("PostCode").Select
.selection.Text = (CStr(DLookup("[PCode]", "tblInsurers",
"[InsurerID] = " & "'" & Me![TPInsurer] & "'")))
.ActiveDocument.Bookmarks("PHRegNum").Select
.selection.Text = (CStr(Me![PHRegNum]))
.ActiveDocument.Bookmarks("AccidentDateTime").Select
.selection.Text = (CStr(Me![AccidentDateTime]))
.ActiveDocument.Bookmarks("TRCref").Select
.selection.Text = (CStr(Me![TRCref]))
.ActiveDocument.Bookmarks("Insured").Select
.selection.Text = (CStr(Me![Phinitials] & " " & Me![Phsurname]))
.ActiveDocument.Bookmarks("TPName").Select
.selection.Text = (CStr(Me![TPinitials] & " " & Me![TPsurname]))
.ActiveDocument.Bookmarks("TPIref").Select
.selection.Text = (CStr(Me![TPInsurerref]))
.ActiveDocument.Bookmarks("InstOffice").Select
.selection.Text = (CStr(DLookup("[PrincipalName]",
"tblPrincipal", "[PrincipalID] = " & "'" & Me![Principal] & "'")))
.ActiveDocument.Bookmarks("TPRegNum").Select
.selection.Text = (CStr(Me![TPRegNum]))
.ActiveDocument.Bookmarks("Insurer").Select
.selection.Text = (CStr(Me![Principal]))
.ActiveDocument.Bookmarks("Office").Select
.selection.Text = (CStr(Me![Ourbranch]))
End With
Set objWord = Nothing
Exit_cmdTPILetter_Click:
Exit Sub
Err_cmdTPILetter_Click:
If Err.Number = 94 Then
objWord.selection.Text = ""
Resume Next
End If
End Sub
template with data from fields in an Access 97 database. The database is
on an server running NT Server 4, with the templates on each client
machine (located at C:\Standard Letters\Templates).
I have a mixture of NT4 Workstation and XP Pro client machines.
Everything works great on the NT machines, and when logged in with
administrator privileges on the XP machines.
However, when logged on as a normal user (a member of "Domain Users"
using a roaming profile) on the XP machines, Word is started and the
relevant template is loaded, but no data is pulled across from Access.
I've had a dig around the MS KB and Google Groups but have not found any
pointers towards a solution yet. As such, I'd be grateful for any
suggestions.
Duncan McKenzie
TRC Ltd.
-----------
start paste
-----------
Private Sub cmdTPILetter_Click()
Dim objWord As Object
Dim WordWasNotRunning As Boolean ' Flag for final release.
On Error Resume Next
Set objWord = GetObject(, "Word.Application")
If Err.Number <> 0 Then WordWasNotRunning = True
Err.Clear ' Clear Err object in case error occurred.
DetectWord
On Error GoTo Err_cmdTPILetter_Click
If WordWasNotRunning Then
Set objWord = CreateObject("Word.Application")
End If
With objWord
.Visible = True
Debug.Print Me![TPInsurer]
Debug.Print "[InsurerID] = " & "'" & Me![TPInsurer] & "'"
.Documents.Add Template:="c:\Standard
Letters\Templates\TPIgenrep.dot"
.ActiveDocument.Bookmarks("PHCompName").Select
.selection.Text = (CStr(DLookup("[CompanyName]", "tblInsurers",
"[InsurerID] = " & "'" & Me![TPInsurer] & "'")))
.ActiveDocument.Bookmarks("Address").Select
.selection.Text = (CStr(DLookup("[OfficeAddress]",
"tblInsurers", "[InsurerID] = " & "'" & Me![TPInsurer] & "'")))
.ActiveDocument.Bookmarks("Location").Select
.selection.Text = (CStr(DLookup("[Location]", "tblInsurers",
"[InsurerID] = " & "'" & Me![TPInsurer] & "'")))
.ActiveDocument.Bookmarks("PostTown").Select
.selection.Text = (CStr(DLookup("[Posttown]", "tblInsurers",
"[InsurerID] = " & "'" & Me![TPInsurer] & "'")))
.ActiveDocument.Bookmarks("PostCode").Select
.selection.Text = (CStr(DLookup("[PCode]", "tblInsurers",
"[InsurerID] = " & "'" & Me![TPInsurer] & "'")))
.ActiveDocument.Bookmarks("PHRegNum").Select
.selection.Text = (CStr(Me![PHRegNum]))
.ActiveDocument.Bookmarks("AccidentDateTime").Select
.selection.Text = (CStr(Me![AccidentDateTime]))
.ActiveDocument.Bookmarks("TRCref").Select
.selection.Text = (CStr(Me![TRCref]))
.ActiveDocument.Bookmarks("Insured").Select
.selection.Text = (CStr(Me![Phinitials] & " " & Me![Phsurname]))
.ActiveDocument.Bookmarks("TPName").Select
.selection.Text = (CStr(Me![TPinitials] & " " & Me![TPsurname]))
.ActiveDocument.Bookmarks("TPIref").Select
.selection.Text = (CStr(Me![TPInsurerref]))
.ActiveDocument.Bookmarks("InstOffice").Select
.selection.Text = (CStr(DLookup("[PrincipalName]",
"tblPrincipal", "[PrincipalID] = " & "'" & Me![Principal] & "'")))
.ActiveDocument.Bookmarks("TPRegNum").Select
.selection.Text = (CStr(Me![TPRegNum]))
.ActiveDocument.Bookmarks("Insurer").Select
.selection.Text = (CStr(Me![Principal]))
.ActiveDocument.Bookmarks("Office").Select
.selection.Text = (CStr(Me![Ourbranch]))
End With
Set objWord = Nothing
Exit_cmdTPILetter_Click:
Exit Sub
Err_cmdTPILetter_Click:
If Err.Number = 94 Then
objWord.selection.Text = ""
Resume Next
End If
End Sub