S
SHIPP
I am getting the following error every 2nd time I run the code below.
Runtime Error 462
The remote server machine does not exist or is unavailable.
It is strange. I am not using a remote server. And it happens exactly every
second time I run the code.
The error occurs at the line.
With ActiveDocument.PageSetup
Help, Please.
Public Sub sWordXport(strSaveTo As String)
'***************************************************************************************
'* PROGRAM : TRN
'* CREATED : 8/5/08
'* COMMENTS : Validates the current record
'* PARAMETERS: -
'* RETURNS : Boolean -
'* CALLED BY :
'* MODIFIED :
'***************************************************************************************
On Error GoTo HandleErr
Const cstrProcName As String = "modCDOEmail - sWordXport"
Dim db As DAO.Database
Dim rs As DAO.Recordset
Dim fld As Field
Dim strHdr As String
Dim strUnique As String
Dim objWord As Word.Application
Dim wDoc As Word.Document
' Set objWord = CreateObject("Word.Application")
' Set objWord = New Word.Application
' objWord.Documents.Add
' Set doc = objWord.ActiveDocument
' objWord.Visible = True
Set objWord = CreateObject("Word.Application")
' Set objWord = GetObject(, "Word.Application")
objWord.Documents.Add
' Set doc = objWord.ActiveDocument
objWord.Visible = True
Set db = CurrentDb()
Set rs = db.OpenRecordset("qryWordExport")
With ActiveDocument.PageSetup
.LineNumbering.Active = False
.Orientation = wdOrientPortrait
.TopMargin = InchesToPoints(1)
.BottomMargin = InchesToPoints(0.5)
.LeftMargin = InchesToPoints(0.5)
.RightMargin = InchesToPoints(0.5)
.Gutter = InchesToPoints(0)
.HeaderDistance = InchesToPoints(0.5)
.FooterDistance = InchesToPoints(0.5)
.PageWidth = InchesToPoints(8.5)
.PageHeight = InchesToPoints(11)
.FirstPageTray = wdPrinterDefaultBin
.OtherPagesTray = wdPrinterDefaultBin
.SectionStart = wdSectionNewPage
.OddAndEvenPagesHeaderFooter = False
.DifferentFirstPageHeaderFooter = False
.VerticalAlignment = wdAlignVerticalTop
.SuppressEndnotes = False
.MirrorMargins = False
.TwoPagesOnOne = False
.BookFoldPrinting = False
.BookFoldRevPrinting = False
.BookFoldPrintingSheets = 1
.GutterPos = wdGutterPosLeft
End With
' Create Header
ActiveWindow.ActivePane.View.SeekView = wdSeekCurrentPageHeader
Selection.TypeText Text:="CONTRA COSTA SUPERIOR COURT"
Selection.TypeParagraph
Selection.TypeText Text:="MARTINEZ, CALIFORNIA"
Selection.TypeParagraph
Selection.TypeText Text:="DEPARTMENT: " & GetDept()
Selection.TypeParagraph
Selection.TypeText Text:="HEARING DATE: " & GetDateBeg()
Selection.WholeStory
Selection.ParagraphFormat.Alignment = wdAlignParagraphCenter
Selection.Font.Size = 14
Selection.Font.Name = "Arial"
ActiveWindow.ActivePane.View.SeekView = wdSeekMainDocument
' Create table
ActiveDocument.Tables.Add Range:=Selection.Range, NumRows:=20, NumColumns _
:=4, DefaultTableBehavior:=wdWord9TableBehavior ', AutoFitBehavior:= _
wdAutoFitFixed
With Selection.Tables(1)
If .Style <> "Table Grid" Then
.Style = "Table Grid"
End If
.ApplyStyleHeadingRows = True
.ApplyStyleLastRow = True
.ApplyStyleFirstColumn = True
.ApplyStyleLastColumn = True
End With
Selection.SelectColumn
Selection.Columns.PreferredWidthType = wdPreferredWidthPoints
Selection.Columns.PreferredWidth = InchesToPoints(0.1)
Selection.SelectCell
Selection.TypeText Text:="H"
Selection.MoveRight Unit:=wdCell
Selection.SelectColumn
Selection.Columns.PreferredWidthType = wdPreferredWidthPoints
Selection.Columns.PreferredWidth = InchesToPoints(0.1)
Selection.SelectCell
Selection.TypeText Text:="S"
Selection.MoveRight Unit:=wdCell
Selection.SelectColumn
Selection.Columns.PreferredWidthType = wdPreferredWidthPoints
Selection.Columns.PreferredWidth = InchesToPoints(0.1)
Selection.SelectCell
Selection.TypeText Text:="T"
Selection.MoveRight Unit:=wdCell
Selection.SelectColumn
Selection.Columns.PreferredWidthType = wdPreferredWidthPoints
Selection.Columns.PreferredWidth = InchesToPoints(6.7)
Selection.SelectCell
Selection.TypeText Text:="TENTATIVE RULING"
' Create the data
rs.MoveLast
rs.MoveFirst
' Create the first Header
Selection.MoveRight Unit:=wdCell
Selection.TypeText Text:="C"
Selection.MoveRight Unit:=wdCell
Selection.MoveRight Unit:=wdCell
Selection.MoveRight Unit:=wdCell
strHdr = rs("UniqueIdnt") & "." & "TIME: " & rs("TrnTime") & "CASE #" &
rs("CaseNo")
strHdr = strHdr & vbCr & "CASE NAME: " & rs("TrnName") & vbCr
strHdr = strHdr & rs("TrnDesc1")
Selection.TypeText Text:=strHdr
Selection.SelectCell
Selection.Font.Name = "Arial"
Selection.Font.Bold = wdToggle
While Not rs.EOF
strUnique = rs("UniqueIdnt")
Selection.MoveRight Unit:=wdCell
If Not IsNull(rs("TrnHdr")) Or Trim(rs("TrnHdr")) <> "" Then
Selection.TypeText Text:="H"
Else
Selection.TypeText Text:="D"
End If
Selection.MoveRight Unit:=wdCell
If Not IsNull(rs("sTrnID")) Then
Selection.TypeText Text:=rs("sTrnID")
End If
Selection.MoveRight Unit:=wdCell
If Not IsNull(rs("TrnID")) Then
Selection.TypeText Text:=rs("TrnID")
End If
Selection.MoveRight Unit:=wdCell
If Not IsNull(rs("TrnHdr")) Or Trim(rs("TrnHdr")) <> "" Then
Selection.TypeText Text:=rs("TrnHdr")
Selection.SelectCell
Selection.Font.Name = "Arial"
Selection.Font.Italic = wdToggle
Selection.Font.Bold = wdToggle
' If Selection.Font.Underline = wdUnderlineNone Then
Selection.Font.Underline = wdUnderlineSingle
' Else
' Selection.Font.Underline = wdUnderlineNone
' End If
With Selection.ParagraphFormat
.LeftIndent = InchesToPoints(0)
.RightIndent = InchesToPoints(0)
.SpaceBefore = 12
.SpaceBeforeAuto = False
.SpaceAfter = 0
.SpaceAfterAuto = False
.LineSpacingRule = wdLineSpaceSingle
.Alignment = wdAlignParagraphLeft
.WidowControl = True
.KeepWithNext = False
.KeepTogether = False
.PageBreakBefore = False
.NoLineNumber = False
.Hyphenation = True
.FirstLineIndent = InchesToPoints(0)
.OutlineLevel = wdOutlineLevelBodyText
.CharacterUnitLeftIndent = 0
.CharacterUnitRightIndent = 0
.CharacterUnitFirstLineIndent = 0
.LineUnitBefore = 0
.LineUnitAfter = 0
End With
End If
Selection.MoveRight Unit:=wdCell
If Not IsNull(rs("TrnDtl")) Or Trim(rs("TrnDtl")) <> "" Then
Selection.TypeText Text:="D"
Selection.MoveRight Unit:=wdCell
Selection.TypeText Text:=rs("sTrnID")
Selection.MoveRight Unit:=wdCell
Selection.TypeText Text:=rs("TrnID")
Selection.MoveRight Unit:=wdCell
Selection.TypeText Text:=rs("TrnDtl")
Selection.SelectCell
Selection.Font.Name = "Arial"
With Selection.ParagraphFormat
.LeftIndent = InchesToPoints(0.2)
.RightIndent = InchesToPoints(0)
.SpaceBefore = 0
.SpaceBeforeAuto = False
.SpaceAfter = 0
.SpaceAfterAuto = False
.LineSpacingRule = wdLineSpaceSingle
.Alignment = wdAlignParagraphLeft
.WidowControl = True
.KeepWithNext = False
.KeepTogether = False
.PageBreakBefore = False
.NoLineNumber = False
.Hyphenation = True
.FirstLineIndent = InchesToPoints(0)
.OutlineLevel = wdOutlineLevelBodyText
.CharacterUnitLeftIndent = 0
.CharacterUnitRightIndent = 0
.CharacterUnitFirstLineIndent = 0
.LineUnitBefore = 0
.LineUnitAfter = 0
End With
Else
Selection.MoveLeft Unit:=wdCell
End If
rs.MoveNext
' Create the next Header
If Not rs.EOF Then
If strUnique <> rs("UniqueIdnt") Then
Selection.MoveRight Unit:=wdCell
Selection.TypeText Text:="C"
Selection.MoveRight Unit:=wdCell
Selection.MoveRight Unit:=wdCell
Selection.MoveRight Unit:=wdCell
strHdr = rs("UniqueIdnt") & "." & "TIME: " & rs("TrnTime") & "CASE
#" & rs("CaseNo")
strHdr = strHdr & vbCr & "CASE NAME: " & rs("TrnName") & vbCr
strHdr = strHdr & rs("TrnDesc1")
Selection.TypeText Text:=strHdr
Selection.SelectCell
Selection.Font.Name = "Arial"
Selection.Font.Bold = wdToggle
End If
End If
Wend
Selection.MoveLeft Unit:=wdCell
Selection.SelectColumn
Selection.Font.Name = "Arial"
Selection.Font.Size = 8
Selection.MoveLeft Unit:=wdCell
Selection.MoveLeft Unit:=wdCell
Selection.SelectColumn
Selection.Font.Name = "Arial"
Selection.Font.Size = 8
Selection.MoveLeft Unit:=wdCell
Selection.MoveLeft Unit:=wdCell
Selection.SelectColumn
Selection.Font.Name = "Arial"
Selection.Font.Size = 8
ActiveDocument.SaveAs FileName:=strSaveTo, FileFormat:=wdFormatDocument, _
LockComments:=False, Password:="", AddToRecentFiles:=True, WritePassword _
:="", ReadOnlyRecommended:=False, EmbedTrueTypeFonts:=False, _
SaveNativePictureFormat:=False, SaveFormsData:=False, SaveAsAOCELetter:= _
False
ExitHere:
objWord.Documents.Close
objWord.Quit
Set objWord = Nothing
rs.Close
db.Close
Set rs = Nothing
Set db = Nothing
Exit Sub
HandleErr:
Select Case Err.Number
Case Else
MsgBox "Error " & Err.Number & ": " & Err.Description, vbCritical,
cstrProcName
End Select
GoTo ExitHere
End Sub
Runtime Error 462
The remote server machine does not exist or is unavailable.
It is strange. I am not using a remote server. And it happens exactly every
second time I run the code.
The error occurs at the line.
With ActiveDocument.PageSetup
Help, Please.
Public Sub sWordXport(strSaveTo As String)
'***************************************************************************************
'* PROGRAM : TRN
'* CREATED : 8/5/08
'* COMMENTS : Validates the current record
'* PARAMETERS: -
'* RETURNS : Boolean -
'* CALLED BY :
'* MODIFIED :
'***************************************************************************************
On Error GoTo HandleErr
Const cstrProcName As String = "modCDOEmail - sWordXport"
Dim db As DAO.Database
Dim rs As DAO.Recordset
Dim fld As Field
Dim strHdr As String
Dim strUnique As String
Dim objWord As Word.Application
Dim wDoc As Word.Document
' Set objWord = CreateObject("Word.Application")
' Set objWord = New Word.Application
' objWord.Documents.Add
' Set doc = objWord.ActiveDocument
' objWord.Visible = True
Set objWord = CreateObject("Word.Application")
' Set objWord = GetObject(, "Word.Application")
objWord.Documents.Add
' Set doc = objWord.ActiveDocument
objWord.Visible = True
Set db = CurrentDb()
Set rs = db.OpenRecordset("qryWordExport")
With ActiveDocument.PageSetup
.LineNumbering.Active = False
.Orientation = wdOrientPortrait
.TopMargin = InchesToPoints(1)
.BottomMargin = InchesToPoints(0.5)
.LeftMargin = InchesToPoints(0.5)
.RightMargin = InchesToPoints(0.5)
.Gutter = InchesToPoints(0)
.HeaderDistance = InchesToPoints(0.5)
.FooterDistance = InchesToPoints(0.5)
.PageWidth = InchesToPoints(8.5)
.PageHeight = InchesToPoints(11)
.FirstPageTray = wdPrinterDefaultBin
.OtherPagesTray = wdPrinterDefaultBin
.SectionStart = wdSectionNewPage
.OddAndEvenPagesHeaderFooter = False
.DifferentFirstPageHeaderFooter = False
.VerticalAlignment = wdAlignVerticalTop
.SuppressEndnotes = False
.MirrorMargins = False
.TwoPagesOnOne = False
.BookFoldPrinting = False
.BookFoldRevPrinting = False
.BookFoldPrintingSheets = 1
.GutterPos = wdGutterPosLeft
End With
' Create Header
ActiveWindow.ActivePane.View.SeekView = wdSeekCurrentPageHeader
Selection.TypeText Text:="CONTRA COSTA SUPERIOR COURT"
Selection.TypeParagraph
Selection.TypeText Text:="MARTINEZ, CALIFORNIA"
Selection.TypeParagraph
Selection.TypeText Text:="DEPARTMENT: " & GetDept()
Selection.TypeParagraph
Selection.TypeText Text:="HEARING DATE: " & GetDateBeg()
Selection.WholeStory
Selection.ParagraphFormat.Alignment = wdAlignParagraphCenter
Selection.Font.Size = 14
Selection.Font.Name = "Arial"
ActiveWindow.ActivePane.View.SeekView = wdSeekMainDocument
' Create table
ActiveDocument.Tables.Add Range:=Selection.Range, NumRows:=20, NumColumns _
:=4, DefaultTableBehavior:=wdWord9TableBehavior ', AutoFitBehavior:= _
wdAutoFitFixed
With Selection.Tables(1)
If .Style <> "Table Grid" Then
.Style = "Table Grid"
End If
.ApplyStyleHeadingRows = True
.ApplyStyleLastRow = True
.ApplyStyleFirstColumn = True
.ApplyStyleLastColumn = True
End With
Selection.SelectColumn
Selection.Columns.PreferredWidthType = wdPreferredWidthPoints
Selection.Columns.PreferredWidth = InchesToPoints(0.1)
Selection.SelectCell
Selection.TypeText Text:="H"
Selection.MoveRight Unit:=wdCell
Selection.SelectColumn
Selection.Columns.PreferredWidthType = wdPreferredWidthPoints
Selection.Columns.PreferredWidth = InchesToPoints(0.1)
Selection.SelectCell
Selection.TypeText Text:="S"
Selection.MoveRight Unit:=wdCell
Selection.SelectColumn
Selection.Columns.PreferredWidthType = wdPreferredWidthPoints
Selection.Columns.PreferredWidth = InchesToPoints(0.1)
Selection.SelectCell
Selection.TypeText Text:="T"
Selection.MoveRight Unit:=wdCell
Selection.SelectColumn
Selection.Columns.PreferredWidthType = wdPreferredWidthPoints
Selection.Columns.PreferredWidth = InchesToPoints(6.7)
Selection.SelectCell
Selection.TypeText Text:="TENTATIVE RULING"
' Create the data
rs.MoveLast
rs.MoveFirst
' Create the first Header
Selection.MoveRight Unit:=wdCell
Selection.TypeText Text:="C"
Selection.MoveRight Unit:=wdCell
Selection.MoveRight Unit:=wdCell
Selection.MoveRight Unit:=wdCell
strHdr = rs("UniqueIdnt") & "." & "TIME: " & rs("TrnTime") & "CASE #" &
rs("CaseNo")
strHdr = strHdr & vbCr & "CASE NAME: " & rs("TrnName") & vbCr
strHdr = strHdr & rs("TrnDesc1")
Selection.TypeText Text:=strHdr
Selection.SelectCell
Selection.Font.Name = "Arial"
Selection.Font.Bold = wdToggle
While Not rs.EOF
strUnique = rs("UniqueIdnt")
Selection.MoveRight Unit:=wdCell
If Not IsNull(rs("TrnHdr")) Or Trim(rs("TrnHdr")) <> "" Then
Selection.TypeText Text:="H"
Else
Selection.TypeText Text:="D"
End If
Selection.MoveRight Unit:=wdCell
If Not IsNull(rs("sTrnID")) Then
Selection.TypeText Text:=rs("sTrnID")
End If
Selection.MoveRight Unit:=wdCell
If Not IsNull(rs("TrnID")) Then
Selection.TypeText Text:=rs("TrnID")
End If
Selection.MoveRight Unit:=wdCell
If Not IsNull(rs("TrnHdr")) Or Trim(rs("TrnHdr")) <> "" Then
Selection.TypeText Text:=rs("TrnHdr")
Selection.SelectCell
Selection.Font.Name = "Arial"
Selection.Font.Italic = wdToggle
Selection.Font.Bold = wdToggle
' If Selection.Font.Underline = wdUnderlineNone Then
Selection.Font.Underline = wdUnderlineSingle
' Else
' Selection.Font.Underline = wdUnderlineNone
' End If
With Selection.ParagraphFormat
.LeftIndent = InchesToPoints(0)
.RightIndent = InchesToPoints(0)
.SpaceBefore = 12
.SpaceBeforeAuto = False
.SpaceAfter = 0
.SpaceAfterAuto = False
.LineSpacingRule = wdLineSpaceSingle
.Alignment = wdAlignParagraphLeft
.WidowControl = True
.KeepWithNext = False
.KeepTogether = False
.PageBreakBefore = False
.NoLineNumber = False
.Hyphenation = True
.FirstLineIndent = InchesToPoints(0)
.OutlineLevel = wdOutlineLevelBodyText
.CharacterUnitLeftIndent = 0
.CharacterUnitRightIndent = 0
.CharacterUnitFirstLineIndent = 0
.LineUnitBefore = 0
.LineUnitAfter = 0
End With
End If
Selection.MoveRight Unit:=wdCell
If Not IsNull(rs("TrnDtl")) Or Trim(rs("TrnDtl")) <> "" Then
Selection.TypeText Text:="D"
Selection.MoveRight Unit:=wdCell
Selection.TypeText Text:=rs("sTrnID")
Selection.MoveRight Unit:=wdCell
Selection.TypeText Text:=rs("TrnID")
Selection.MoveRight Unit:=wdCell
Selection.TypeText Text:=rs("TrnDtl")
Selection.SelectCell
Selection.Font.Name = "Arial"
With Selection.ParagraphFormat
.LeftIndent = InchesToPoints(0.2)
.RightIndent = InchesToPoints(0)
.SpaceBefore = 0
.SpaceBeforeAuto = False
.SpaceAfter = 0
.SpaceAfterAuto = False
.LineSpacingRule = wdLineSpaceSingle
.Alignment = wdAlignParagraphLeft
.WidowControl = True
.KeepWithNext = False
.KeepTogether = False
.PageBreakBefore = False
.NoLineNumber = False
.Hyphenation = True
.FirstLineIndent = InchesToPoints(0)
.OutlineLevel = wdOutlineLevelBodyText
.CharacterUnitLeftIndent = 0
.CharacterUnitRightIndent = 0
.CharacterUnitFirstLineIndent = 0
.LineUnitBefore = 0
.LineUnitAfter = 0
End With
Else
Selection.MoveLeft Unit:=wdCell
End If
rs.MoveNext
' Create the next Header
If Not rs.EOF Then
If strUnique <> rs("UniqueIdnt") Then
Selection.MoveRight Unit:=wdCell
Selection.TypeText Text:="C"
Selection.MoveRight Unit:=wdCell
Selection.MoveRight Unit:=wdCell
Selection.MoveRight Unit:=wdCell
strHdr = rs("UniqueIdnt") & "." & "TIME: " & rs("TrnTime") & "CASE
#" & rs("CaseNo")
strHdr = strHdr & vbCr & "CASE NAME: " & rs("TrnName") & vbCr
strHdr = strHdr & rs("TrnDesc1")
Selection.TypeText Text:=strHdr
Selection.SelectCell
Selection.Font.Name = "Arial"
Selection.Font.Bold = wdToggle
End If
End If
Wend
Selection.MoveLeft Unit:=wdCell
Selection.SelectColumn
Selection.Font.Name = "Arial"
Selection.Font.Size = 8
Selection.MoveLeft Unit:=wdCell
Selection.MoveLeft Unit:=wdCell
Selection.SelectColumn
Selection.Font.Name = "Arial"
Selection.Font.Size = 8
Selection.MoveLeft Unit:=wdCell
Selection.MoveLeft Unit:=wdCell
Selection.SelectColumn
Selection.Font.Name = "Arial"
Selection.Font.Size = 8
ActiveDocument.SaveAs FileName:=strSaveTo, FileFormat:=wdFormatDocument, _
LockComments:=False, Password:="", AddToRecentFiles:=True, WritePassword _
:="", ReadOnlyRecommended:=False, EmbedTrueTypeFonts:=False, _
SaveNativePictureFormat:=False, SaveFormsData:=False, SaveAsAOCELetter:= _
False
ExitHere:
objWord.Documents.Close
objWord.Quit
Set objWord = Nothing
rs.Close
db.Close
Set rs = Nothing
Set db = Nothing
Exit Sub
HandleErr:
Select Case Err.Number
Case Else
MsgBox "Error " & Err.Number & ": " & Err.Description, vbCritical,
cstrProcName
End Select
GoTo ExitHere
End Sub