Word Automation sending records to word table

mazza

Registered User.
Local time
Today, 03:29
Joined
Feb 9, 2005
Messages
101
I used some of the code from Pat Hartman to attempt to send a record string to a table in MS Word


In the line Set objTable =
WordApp.Selection.ConvertToTable(Separator:=vbTab) I get a Object required message


I know I am missing some declarations but not sure where & what So no doubt I get some more error mesages when I solve this one.


PS in my function createjobsheet I removed part of the function that works OK in order to keep it easier to look at.


Where do I go wrong

Public Function FinishTable(bkmk As String, strtable As String)
Dim objTable As Word.Table


InsertTextAtBookMark bkmk, strtable
Set objTable = WordApp.Selection.ConvertToTable(Separator:=vbTab)
objTable.AutoFormat Format:=wdTableFormatProfessional, applyshading:=True, applyHeadingrows:=True, AutoFit:=True
' objTable.Rows(1).HeadingFormat = True
WordApp.Selection.MoveRight Unit:=wdCell
WordApp.Selection.Rows.HeadingFormat = wdToggle
'Call SetShading
Set objTable = Nothing

PROC_EXIT:
Exit Function
End Function


Public Function InsertTextAtBookMark(strBkmk As String, varText As Variant)

On Error GoTo PROC_ERR

WordDoc.Bookmarks(strBkmk).Select
WordApp.Selection.Text = varText & ""

PROC_EXIT:
Exit Function

PROC_ERR:
MsgBox Err.Number & " - " & Err.Description
Resume PROC_EXIT

End Function



Function CreateServiceJobSheet()
'On Error Resume Next
Dim db As DAO.Database
Dim rs2 As DAO.Recordset
Dim strtable As String
Dim WordObj As Object
Dim sqlparts As String

Set WordObj = CreateObject("Word.Application")
WordObj.Visible = True

WordObj.Documents.Add "c:\program files\compair service management\servicejob.dot"

Set db = CurrentDb()

'print the parts required

sqlparts = "SELECT TblServiceJobparts.PartNbr, TblServiceJobparts.description, TblServiceJobparts.Qty, TblServiceJobparts.QtyOrdered " & _
"FROM TblServiceJobparts " & _
"WHERE (((TblServiceJobparts.serviceID)= " & [Forms]![FrmServicejobdetails]![serviceId] & "));"

Set rs2 = db.OpenRecordset(sqlparts, dbOpenDynaset, dbSeeChanges)


If rs2.EOF Then
strtable = "No Parts specified" & vbCr
Else
'strtable = "PartNumber" & vbTab & "Description" & vbTab & "Quantity" & vbTab & "ordered" & vbCr
Do Until rs2.EOF
strtable = strtable & CStr(rs2!PartNbr) & vbTab
strtable = strtable & CStr(rs2!Description) & vbTab
strtable = strtable & CStr(rs2!QTY) & vbTab
strtable = strtable & CStr(rs2!QtyOrdered) & vbCr
rs2.MoveNext
Loop

End If
Call FinishTable("BKParts", strtable)


Set WordObj = Nothing
End Function
 

Users who are viewing this thread

Back
Top Bottom