I am using the following code to merge a record to microsoft word:
The code works fine on one of my forms. I create new form and add a button and attach the code to it but I get the error:
.
The error occurs on the line:
Code:
Private Sub cmdMergeIt_Click()
'creates an SQL statement to be used in the query def
On Error GoTo ErrorHandler
DoCmd.SetWarnings False
Me.Refresh
DoCmd.OpenQuery "qryAddTempTitle"
' user enters a zip code in a text box on the form;
' the query's criteria is set to pull records for
'that zip code
'Dim strPostalCode As String
'strPostalCode = txtPostalCode.Value
Dim strSQL As String
'replace the SQL statement below with the SQL statement
'from your query. This sample shows how to use single quotes
'to incorporate string values from the form's fields
'into the SQL statement. For dates, use # instead of the
'single quotes
strSQL = "SELECT TOP 1 TitlesTemp.* FROM TitlesTemp"
Dim strDocumentName As String 'name of the Word template document
strDocumentName = "ReportTemplate.dotx"
'use your template document name above
Call SetQuery("qryGetLastTitle", strSQL)
'use your query name above
Dim strNewName As String 'name to use when saving
'the merged document
'this next line of code makes the document name pattern
'like this: Custom Labels January 11, 2005.doc
'strNewName = "Title Check Report " & Format(CStr(Date), "dd MM yyyy")
strNewName = Me.AccountNumber.Value & "_Title Check Report "
'use your file name pattern above
Call OpenMergedDoc(strDocumentName, strSQL, strNewName)
DoCmd.OpenQuery "qryDeleteTempTitle"
DoCmd.SetWarnings True
Me.Page1.SetFocus
Exit Sub
ErrorHandler:
MsgBox "Error #" & Err.Number & " occurred. " & Err.Description, vbOKOnly, "Error"
Exit Sub
End Sub
The code works fine on one of my forms. I create new form and add a button and attach the code to it but I get the error:
Code:
Compile Error: Sub of Function not defined
The error occurs on the line:
Code:
Call SetQuery("qryGetLastTitle", strSQL)