Look up and output issue in related tables

Chintsapete

Registered User.
Local time
Today, 20:39
Joined
Jun 15, 2012
Messages
137
I'm using below code to output employee info onto word document. It works except, it outputs the title ID instead of the title. The tables "employees" and "title" are many-to-one related and it works everywhere else.
Is there a way to make it look up the title instead of the ID?


Code:
Private Sub Command187_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\NEW REVISED 3 MONTHLY CONTRACT.docx", , True)
appWord.Visible = True
 
With doc
If IsNull(Me.Title) Then
.FormFields("txtTitle").Result = ""
Else
.FormFields("txtTitle").Result = Me.Title    'outputs the table ID and not the title. 
End If

 End With
 Set doc = Nothing
 Set appWord = Nothing
Exit Sub
errHandler:
 MsgBox Err.Number & ": " & Err.Description

End Sub

Many thanks for any help
 
if Me.Title is a combo or list box with a rowsource something like

Select ID, Title from tbltitles

then you need to use the column property

me.title.column(1)
 
Thanks CJ, works perfect. I appreciate it.

Code working below.

Code:
Private Sub Command187_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\NEW REVISED 3 MONTHLY CONTRACT.docx", , True)
appWord.Visible = True
 
With doc
If IsNull(Me.Title) Then
.FormFields("txtTitle").Result = ""
Else
.FormFields("txtTitle").Result = Me.Titel.Column(1)
End If

 End With
 Set doc = Nothing
 Set appWord = Nothing
Exit Sub
errHandler:
 MsgBox Err.Number & ": " & Err.Description

End Sub
 

Users who are viewing this thread

Back
Top Bottom