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.
Can someone help me out? Thanks.
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.