Here we go again...
I have a form that the user fills in with a student's information, then opens a Word document to display a Certificate of Completion. This worked fine in Access 2007. Here is the code...
Private Sub cmdCert_Click()
'Opens Certificate.docx with the correct labels visible
Dim stDocName As String
Dim stLinkCriteria As String
stDocName = "frmCertificate"
'DoCmd.OpenForm stDocName, acViewNormal
Const DOC_PATH As String = "T:\PG Operations\Training Programs\Certificates\"
Const DOC_NAME As String = "CofT.docx"
Dim appWord As Word.Application
Dim doc As Word.Document
On Error Resume Next
Set appWord = GetObject(, "Word.application")
If Err = 429 Then
Set appWord = New Word.Application
Err = 0
End If
With appWord
Set doc = .Documents(DOC_NAME)
If Err = 0 Then
doc.Close False
End If
On Error GoTo ErrorHandler
Set doc = .Documents.Open(DOC_PATH & DOC_NAME, , True)
With doc
.FormFields("EName").Result = Forms!frmCertificate![EName]
.FormFields("Comp").Result = Forms!frmCertificate![Comp]
.FormFields("Inst").Result = Forms!frmCertificate![Inst]
If Me.DTrng <> "" Then
.FormFields("Trng").Result = Forms!frmCertificate![DTrng]
ElseIf Me.STrng <> "" Then
.FormFields("Trng").Result = Forms!frmCertificate![STrng]
ElseIf Me.ETrng <> "" Then
.FormFields("Trng").Result = Forms!frmCertificate![ETrng]
ElseIf Me.ERTrng <> "" Then
.FormFields("Trng").Result = Forms!frmCertificate![ERTrng]
End If
End With
.Visible = True
.Activate
End With
Set rst = Nothing
Set doc = Nothing
Set appWord = Nothing
Exit Sub
ErrorHandler:
MsgBox Err & Err.Description
End Sub
It's hanging up at the "Dim appWord As Word.Application" line with the error message saying "Compile Error: User-defined type not defined. Is there maybe a Reference that I need to check under Tools to get this working again, or does it just need to be written different for Access 2010?