Open word document (1 Viewer)

texas1992

Registered User.
Local time
Yesterday, 20:37
Joined
May 8, 2012
Messages
25
I am not an Access programmer but I have been asked to make some changes to an Access DB.

I need to open a Word template and populate some bookmarks on the template.

I have found code to open the template but I can't get it to open. I get the error:

"Type mismatch".

Here is the code:
Code:
Dim objWord As Object
Set objWord = CreateObject("Word.Application")

Do I need to add a reference or something? I am using the Office 2010 suite.

Thanks.
 

boblarson

Smeghead
Local time
Yesterday, 18:37
Joined
Jan 12, 2001
Messages
32,059
No reference needed but which line does it error on (post your whole procedure's code). The two lines there should not have a problem.
 

texas1992

Registered User.
Local time
Yesterday, 20:37
Joined
May 8, 2012
Messages
25
Here is what is happening:

We are moving to Windows 7 as a company so the database had to be converted from Access 2003 to Access 2010.

Code:
Public Sub PlaintiffSummaryToWord()
Dim conAdo As New ADODB.Connection
Dim rsADO As New ADODB.Recordset
Dim objWord As Object
Dim blnDoTableHeaders As Boolean
 
'Get the plaintiffs that are part of the case.
strreqsql = "select * from qryPlaintiffsSummary WHERE qryPlaintiffsSummary.CaseID = " & [Forms]![frmPlaintiffs]![CaseID]

Set g_rs = g_db.OpenRecordset(strreqsql, dbOpenDynaset)
 
'=============================================
'   THIS IS WHERE I GET THE ERROR
' Open Microsoft Word using automation
Set objWord = CreateObject("Word.Application")
'=============================================

I get the error just above where I am trying to get create an instance of Word.

I HTH.
 

boblarson

Smeghead
Local time
Yesterday, 18:37
Joined
Jan 12, 2001
Messages
32,059
Here is what is happening:

We are moving to Windows 7 as a company so the database had to be converted from Access 2003 to Access 2010.
Actually, you don't have to convert the database from 2003 format to 2010 format. 2003 format works just fine in 2010. In fact, unless there is a really good reason to convert it, I wouldn't. I would just use it in the same file format.

So, if you have tried to save it as a 2010 version, how did you do it? The only sure way of converting that I've found is to IMPORT (not copy/paste, or do the save as file type) into a brand new, 2010 accdb file from the 2003 mdb file.

And by the way this is off subject but if you are going to use the ADO to refer to this current database, you should change your connection object declaration from
Dim conAdo As New ADODB.Connection

to

Dim conAdo As ADODB.Connection

and then assign it like

Set conAdo = CurrentProject.Connection

so you don't open too many connections to the same file which can cause problems. If referring to the same database that the code is in, using CurrentProject.Connection is definitely the preferred way of doing it.


Also, you stated that you are getting the error when you use the CreateObject code, but then you stated:
I get the error just above where I am trying to get create an instance of Word.
Just above to me looks like the line
Code:
Set g_rs = g_db.OpenRecordset(strreqsql, dbOpenDynaset)

And my question is - is g_db declared as a DAO.Database? And is g_rs declared as a DAO.Recordset? Or did you just use Recordset? You may need to disambiguate that to DAO.Recordset.
 

texas1992

Registered User.
Local time
Yesterday, 20:37
Joined
May 8, 2012
Messages
25
Thanks for the tips. I will put them to use.

I did not create nor did I convert this database but I am tasked with making the changes.

Here are the declarations for the global variables in question:

Global g_db As Database
Global g_rs As Recordset
 

boblarson

Smeghead
Local time
Yesterday, 18:37
Joined
Jan 12, 2001
Messages
32,059
Change this one:

Global g_rs As Recordset

to this

Global g_rs As DAO.Recordset

And I'll bet the error goes away (unless you don't have a DAO reference set).
 

texas1992

Registered User.
Local time
Yesterday, 20:37
Joined
May 8, 2012
Messages
25
WOW!! Thanks! You were right, the error went away.
 

Users who are viewing this thread

Top Bottom