Tek-Tips is the largest IT community on the Internet today!

Members share and learn making Tek-Tips Forums the best source of peer-reviewed technical information on the Internet!

  • Congratulations Mike Lewis on being selected by the Tek-Tips community for having the most helpful posts in the forums last week. Way to Go!

Sending data to Word.

Status
Not open for further replies.

Colvic

Programmer
Nov 4, 2005
24
0
0
NO

Hi,
Can anyone tell me why this code is not working.
I try to run this code. It send data to MS Word, but the second times I run it, I get a error message: ' The remote server machine does not exist or is unavailable (Error 462)

It stops in this segment: .Rows(1).Select

Thanks in advance



Here is the code:

Private Sub WordRapport_Click()
Dim objWord As Word.Application

Dim rst As Recordset
Dim strSQL As String

Set objWord = New Word.Application
objWord.Documents.Add Application.CurrentProject.Path & "\Item.dot"

objWord.Visible = True

strSQL = "SELECT tbl_Item.Item1, tbl_Item.Item2, tbl_Item.Item3 FROM tbl_Item;"


Set rst = New Recordset

rst.Open strSQL, CurrentProject.Connection

With CreateTableFromRecordset(objWord.ActiveDocument.Bookmarks("Mandag").Range, rst, True)

' The remote server machine does not exist or is unavailable (Error 462)
.Rows(1).Select
With Selection.Font
.Name = "Arial"
.Size = 12
.Bold = True
.AllCaps = True
.Color = wdColorBlue
End With
End With

rst.Close
Set objWord = Nothing
Set rst = Nothing
End Sub


Function CreateTableFromRecordset(rngAny As Word.Range, rstAny As ADODB.Recordset, Optional fIncludeFieldNames As Boolean = False) As Word.Table

Dim objTable As Word.Table
Dim fldAny As ADODB.Field
Dim varData As Variant
Dim strBookmark As String
Dim cField As Long

varData = rstAny.GetString()

With rngAny
.InsertAfter varData
Set objTable = .ConvertToTable(Separator:=wdSeparateByTabs)
If fIncludeFieldNames Then
With objTable
.Rows.Add(.Rows(1)).HeadingFormat = True
For Each fldAny In rstAny.Fields
cField = cField + 1
.Cell(1, cField).Range.Text = fldAny.Name
Next
End With
End If
End With
Set CreateTableFromRecordset = objTable
End Function
 
Replace this:
With Selection.Font
with something like this:
With objWord.Selection.Font

Hope This Helps, PH.
Want to get great answers to your Tek-Tips questions? Have a look at FAQ219-2884 or FAQ181-2886
 
Status
Not open for further replies.

Part and Inventory Search

Sponsor

Back
Top