Run Time error 13 Type mismatch (1 Viewer)

JPR

Registered User.
Local time
Yesterday, 20:26
Joined
Jan 23, 2009
Messages
192
Hello,
back for some help. Almost finished by project but coming up with a type mismatch error 13 which I just cannot solve.
The code behind my cmdbutton exports date from my form to a MS Word Template.
Data is stored in textboxes and combo boxes. When I run the code I get the error message at the code line which should export data from a combo.

The following codes searches for the template:
Code:
strPath = DLookup("[TemplateLocation]", "TablePath", "[TemplateID]='" & Me.[txtpathLetter] & "'")

Set objWord = CreateObject("Word.Application")
objWord.Visible = False
objWord.Documents.Add strPath

[/CODE]

This is the code that export data from a text box to the template:

Code:
objWord.ActiveDocument.Bookmarks("STATUS").Select
objWord.Selection.Text = Me.STATUS

The error highlights the line: objWord.Selection.Text = Me.STATUS

Data in the field Status is short text.

Appreciate your help. Thank you
 

theDBguy

I’m here to help
Staff member
Local time
Yesterday, 20:26
Joined
Oct 29, 2018
Messages
21,455
Hi. Status shouldn't be a reserved word but try enclosing it in square brackets just to see if it makes any difference.
 

gemma-the-husky

Super Moderator
Staff member
Local time
Today, 04:26
Joined
Sep 12, 2006
Messages
15,641
What is status? A named block of text, or the contents of a text box?

Maybe me.status isn't the correct syntax. It sounds a bit strange to me, although I have no experience of manipulating Word
 

cheekybuddha

AWF VIP
Local time
Today, 04:26
Joined
Jul 21, 2014
Messages
2,272
If textbox Me.STATUS is empty, its value might be Null which would cause the type mismatch.

You can also try:
Code:
' ...
objWord.Selection.Text = Me.STATUS & vbNullString
 

The_Doc_Man

Immoderate Moderator
Staff member
Local time
Yesterday, 22:26
Joined
Feb 28, 2001
Messages
27,148
I don't claim to be an expert here, but instead of making the .Text be substituted at the bookmark, have you tried using either the .InsertAfter or .InsertParagraphAfter methods?
 

JPR

Registered User.
Local time
Yesterday, 20:26
Joined
Jan 23, 2009
Messages
192
Hello. I am sorry but have never used the .InsertAfter or .InsertparagraphAfter methods.
 

arnelgp

..forever waiting... waiting for jellybean!
Local time
Today, 11:26
Joined
May 7, 2009
Messages
19,229
you lack the Range property and you don't need Selection.Text.
also don't you think you need to Open the Word document instead of Add?

Code:
objWord.ActiveDocument.Bookmarks("STATUS").Range.Text = Me.STATUS
'objWord.Selection.Text = Me.STATUS
 

JPR

Registered User.
Local time
Yesterday, 20:26
Joined
Jan 23, 2009
Messages
192
hello, I have modified the code replacing the add with the .Range.Text = MeXXXX.
I noticed that the result is the same although not sure what is the main difference between the two lines of code. Thanks
 

Users who are viewing this thread

Top Bottom