Exporting to Word and Remote Server Unavailable Error (1 Viewer)

Starman

Captain Noble
Local time
Today, 05:07
Joined
Jan 25, 2007
Messages
45
I looked at a couple of threads here on this topic and tried some suggestions, but was unable to fix my problem.

I am exporting some data to a Word template so that users can then write an incident report (its for our security dept). Everything seems to work fine except that I keep getting the "Remote server does not exist blah blah blah" error. Here is the code.

Code:
Public Function MergetoWord()
On Error GoTo Err_Handler

    Dim objWordApp As Word.Application
    Dim objWord As Word.Document
    Dim strMyTemplatePath As String
    Dim strSaveLoc As String
    Dim strSQL As String
    Dim strSQL2 As String
    Dim lngNewReportID As Long
    Dim intRptNumber As Long
    Dim intOffNumber As Integer
    Dim strOfficerName As String
    Dim strSupervisor As String
    
    intRptNumber = Me.intReportNumber
    strOfficerName = Me.cboOfficer.Column(1)
    strSupervisor = Me.cboSupervisor.Column(1)
    intOffNumber = Me.cboOfficer
    
    DoCmd.Close
    
    Set objWordApp = CreateObject("Word.Application")
    objWordApp.Visible = True
    
    strMyTemplatePath = "C:\Users\Valued Customer\Documents\Work\Public Safety\CC2\Templates\ReportTemplate.dot"
    Set objWord = objWordApp.Documents.Add(strMyTemplatePath)
    
    objWord.FormFields("Category").Result = Forms!frmIncident.[LogCategory]
    objWord.FormFields("Subcategory").Result = Forms!frmIncident.[LogSubCategory]
    objWord.FormFields("Building").Result = Forms!frmIncident.[Building]
    objWord.FormFields("Floor").Result = Forms!frmIncident.[Floor]
    objWord.FormFields("Location").Result = Forms!frmIncident.[Location]
    objWord.FormFields("StartDate").Result = Forms!frmIncident.[StartDate]
    objWord.FormFields("StartTime").Result = Forms!frmIncident.[StartTime]
    objWord.FormFields("EndDate").Result = Forms!frmIncident.[EndDate]
    objWord.FormFields("EndTime").Result = Forms!frmIncident.[EndTime]
    objWord.FormFields("FileNumber").Result = intRptNumber
    objWord.FormFields("ReportingOfficer").Result = strOfficerName
    objWord.FormFields("SupervisingOfficer").Result = strSupervisor
    objWord.FormFields("DateWritten").Result = Date
    
    strSaveLoc = "C:\Users\Valued Customer\Documents\Work\Public Safety\CC2\Templates\" & intRptNumber & ".doc"
    objWord.SaveAs strSaveLoc
    
    strSQL = "INSERT INTO tblIncidentReport(OfficerID,IncidentReportNumber,IncidentReportLocation,DateWritten) " & _
            "VALUES (" & intOffNumber & ", " & intRptNumber & ", '" & strSaveLoc & "'" & ", " & "#" & Date & "#" & ")"
            
    DoCmd.SetWarnings False
    DoCmd.RunSQL strSQL
    DoCmd.SetWarnings True
    
    lngNewReportID = DLookup("[IncidentReportID]", "tblIncidentReport", "[IncidentReportNumber]= " & intRptNumber)
    
    strSQL2 = "INSERT INTO tblLINKIncident_IncidentReport(IncidentID, IncidentReportID) " & _
            "VALUES (" & Forms!frmIncident.IncidentID & ", " & lngNewReportID & ")"
            
    DoCmd.SetWarnings False
    DoCmd.RunSQL strSQL2
    DoCmd.SetWarnings True
    
    objWord.ActiveWindow.Activate
    Selection.GoTo What:=wdGoToBookmark, Name:="Narrative"

Exit_Routine:
    Set objWord = Nothing
    Set objWordApp = Nothing
    Exit Function

Err_Handler:
    Set objWord = Nothing
    Set objWordApp = Nothing
    MsgBox "An error has occurred. Please contact your application administrator and give him " & _
            "the following information:" & vbCrLf & vbCrLf & _
            "Error: " & Err.Number & " - " & Err.Description, vbCritical, "Command Center"
            
    Resume Exit_Routine
    Resume

End Function

Can someone help me out? Thanks.
 

DCrake

Remembered
Local time
Today, 11:07
Joined
Jun 8, 2005
Messages
8,632
Which line is the error generated on? dim out the On Error line and retry.

Are you on the remote server when you are running this code?
 

ErikSnoek

Programmer
Local time
Today, 04:07
Joined
Apr 26, 2007
Messages
100
This line could be the problem:
Code:
Selection.GoTo What:=wdGoToBookmark, Name:="Narrative"

Change it to:
Code:
objWord.Selection.GoTo What:=wdGoToBookmark, Name:="Narrative"
and try again.

Another possible reason could be the fact that you're not calling "objWordApp.Quit", try adding that before "Set objWordApp = Nothing"
 

Starman

Captain Noble
Local time
Today, 05:07
Joined
Jan 25, 2007
Messages
45
Okay, it is this line that is giving me trouble.

Code:
Selection.GoTo What:=wdGoToBookmark, Name:="Narrative"

If I change it to:

Code:
objWord.Selection.GoTo What:=wdGoToBookmark, Name:="Narrative"

I get an error saying this object does not support that property.

I am not running this on a network; I am still just testing it locally on my computer. I also did not want to put in objWordApp.Quit because that closes Word before the user has a chance to add their narrative.
 

Starman

Captain Noble
Local time
Today, 05:07
Joined
Jan 25, 2007
Messages
45
I think I finally figured it out. I changed these lines:

Code:
    [FONT=Verdana]objWord.ActiveWindow.Activate[/FONT][FONT=Verdana]
Selection.GoTo What:=wdGoToBookmark, Name:="Narrative"[/FONT]

to this:

Code:
objWord.ActiveWindow.Selection.GoTo What:=wdGoToBookmark, Name:="Narrative"

And now I'm not getting the "Remote Server" error.
 

Users who are viewing this thread

Top Bottom