VBA 2007 to 2010 conversion issue

Steve400

Registered User.
Local time
Tomorrow, 06:54
Joined
May 1, 2013
Messages
33
I had this code working in Access 2007 to create emails from Outlook and populate them. THere had bee nan upgrade to 2010 and now I'm getting a run-time error 13 (type mismathc) on the line to Set NewDoc....
Any ideas? I can't figure this out.
thanks in advance


Private Sub SendEmail_Click()
Dim db As DAO.Database
Dim rsEmailList As DAO.Recordset
Dim AuditLog As DAO.Recordset
Dim path As String
Dim objWord As Object
Dim FileN As String
Dim NewDoc As Word.Document
Dim RetVal

'URL folder of Template
path = "S:\test\" & Me.Attachment & ".doc"

Set db = CurrentDb
Set rsEmailList = db.OpenRecordset("EmailList", dbOpenSnapshot)
Set AuditLog = db.OpenRecordset("AuditEmails")

With rsEmailList
Do Until rsEmailList.EOF

'if recordset is not empty
If IsNull(.Fields("Email")) = False Then

'if there is an attachment selected
If (Right(Me.Attachment, 8) = "Template" Or Right(Me.Attachment, 13) = "Questionnaire" Or Right(Me.Attachment, 8) = "Document") Then
Set objWord = CreateObject("word.application")
objWord.Visible = True
Set NewDoc = objWord.Documents.Open(path)
 
Thanks Bob,
That's helpful.

I Dim'ed NewDoc as an object and for some reason had to add a line of code to open the template before setting it as NewDoc.
Not really sure why this fixed the issue but it did.

The template was still saved in 2007 format so I didn't change the extension to .docx.

Good result.
Thanks again
 

Users who are viewing this thread

Back
Top Bottom