Chintsapete
Registered User.
- Local time
- Today, 11:01
- Joined
- Jun 15, 2012
- Messages
- 137
I want to automate employment contracts. In my form in the payroll I fill in all the details and select what department they work in a press a button and it selects the template fills in all the FormText fiels and inserts the document for each department's Job description.
I made word a word document with FormText fields and populate them from access 2007 with code below, which works sweet (I cut some of the code). What doesn't work is to insert another document into the bookmark "txtJobDesc", I always get the error "462: The remote server machine does not exist or is unavailable". I did read hundreds of posts and tried different variations but for some reason I cant come right with this.
Any help appreciated.
Another option I tried (Error code 424: Object required)
I made word a word document with FormText fields and populate them from access 2007 with code below, which works sweet (I cut some of the code). What doesn't work is to insert another document into the bookmark "txtJobDesc", I always get the error "462: The remote server machine does not exist or is unavailable". I did read hundreds of posts and tried different variations but for some reason I cant come right with this.
Any help appreciated.
Code:
Private Sub Command188_Click()
Dim appWord As Object
Dim doc As Word.Document
On Error Resume Next
Error.Clear
Set appWord = GetObject("Word.Application")
If Error <> 0 Then
Set appWord = New Word.Application
End If
On Error GoTo errHandler
Set doc = appWord.Documents.Open("C:\Users\Server-new\Documents\Accounting\Payroll\BuccaneersContractPermanent.dotm", , True)
appWord.Visible = True
With doc
If IsNull(Me.Titel) Then
.FormFields("txtTitle").Result = ""
Else
.FormFields("txtTitle").Result = Me.Titel.Column(1)
End If
If IsNull(Me.FirstName) Then
.FormFields("txtFirstName").Result = ""
Else
.FormFields("txtFirstName").Result = Me.FirstName
End If
'Copy and Paste Job description doesn't work
If IsNull(Me.Department) Then
.FormFields("txtJobDesc").Result = ""
ElseIf (Me.Department.Column(1)) = "Bar" Then
ActiveDocument.Bookmarks("txtJobDesc").Select
Selection.InsertFile FileName = "C:\Users\Server-new\Documents\Accounting\Payroll\Barman Job Description.docx"
End If
If IsNull(Me.DateOfEngagment) Then
.FormFields("txtDOE").Result = ""
Else
.FormFields("txtDOE").Result = Me.DateOfEngagment
End If
End With
Set doc = Nothing
Set appWord = Nothing
Exit Sub
errHandler:
MsgBox Err.Number & ": " & Err.Description
End Sub
Another option I tried (Error code 424: Object required)
Code:
'Copy and Paste Job description
If IsNull(Me.Department) Then
.FormFields("txtJobDesc").Result = ""
ElseIf (Me.Department.Column(1)) = "Bar" Then
Set objWord = CreateObject(“Word.Application”)
objWord.Visible = True
Set objDoc = objWord.Documents.Add()
Set objSelection = objWord.Selection
objSelection.TypeText "Job description Barman "
ActiveDocument.FormFields("txtJobDesc").Select
objSelection.InsertFile = ("C:\Users\Server-new\Documents\Accounting\Payroll\Barman Job Description.docx")
End If