N
naigy
Hi I have been trying for a couple of days now and researching on various
forums and tutorials and I just can't seem to get this to work. I have two
fields (only trying one at the moment) that I want to copy from a form to a
word template when a button is pushed on a form. I have included two examples
which I have tried with the following errors
Example 1 Gives the following error. Run-time error '5941': The requested
member of the collection does not exist.
Sub Command39_Click()
Dim MyWord As Word.Application
Dim PathDocu As String
Set MyWord = New Word.Application
PathDocu = "C:\"
With MyWord
.Documents.Open (PathDocu & "QCATS.dot")
.ActiveDocument.Bookmarks("Serial").Select ' If I remove the ""
from around Serial then in the debug window when I mouse over that the
current value pops up in a textbox. It also pops up when mouse over the Me.
Serial on the following line. However everyone seems to have the "" in there
examples everywhere. Either way I still get the above error message.
.ActiveDocument.Selection.Text = Me.Serial
..Visible = True
End With
End Sub
Example 2 Gives the following error. Run-time error '5101': This bookmark
does not exist. The weird thing is though if I mouse over the Name =
Bookmark1 I get bookmark1=empty pop up in a text box if I am in a debug
window. If I change this to Bookmark2 (which doesn't exist in the word doc)
then it doesn't pop up.
Private Sub Command42_Click()
Dim wd As Word.Application
Dim myDoc As Word.Document
Set wd = New Word.Application
wd.Documents.Add "c:\Delete.Doc"
Set myDoc = wd.ActiveDocument
With wd.Selection
.GoTo wdGoToBookmark, Name:=Bookmark1
.Font.Bold = True ' You can choose if bold
.Font.Underline = False ' or underline
.TypeText Text:=Me.Serial
End With
wd.Visible = True
End Sub
Can someone please help to clear up the error in one of the above two
examples. Once I solve this I need to work out how to get it to open a
different word template depending on another field in the form.
Thanks for any assistance you may be able to provide.
forums and tutorials and I just can't seem to get this to work. I have two
fields (only trying one at the moment) that I want to copy from a form to a
word template when a button is pushed on a form. I have included two examples
which I have tried with the following errors
Example 1 Gives the following error. Run-time error '5941': The requested
member of the collection does not exist.
Sub Command39_Click()
Dim MyWord As Word.Application
Dim PathDocu As String
Set MyWord = New Word.Application
PathDocu = "C:\"
With MyWord
.Documents.Open (PathDocu & "QCATS.dot")
.ActiveDocument.Bookmarks("Serial").Select ' If I remove the ""
from around Serial then in the debug window when I mouse over that the
current value pops up in a textbox. It also pops up when mouse over the Me.
Serial on the following line. However everyone seems to have the "" in there
examples everywhere. Either way I still get the above error message.
.ActiveDocument.Selection.Text = Me.Serial
..Visible = True
End With
End Sub
Example 2 Gives the following error. Run-time error '5101': This bookmark
does not exist. The weird thing is though if I mouse over the Name =
Bookmark1 I get bookmark1=empty pop up in a text box if I am in a debug
window. If I change this to Bookmark2 (which doesn't exist in the word doc)
then it doesn't pop up.
Private Sub Command42_Click()
Dim wd As Word.Application
Dim myDoc As Word.Document
Set wd = New Word.Application
wd.Documents.Add "c:\Delete.Doc"
Set myDoc = wd.ActiveDocument
With wd.Selection
.GoTo wdGoToBookmark, Name:=Bookmark1
.Font.Bold = True ' You can choose if bold
.Font.Underline = False ' or underline
.TypeText Text:=Me.Serial
End With
wd.Visible = True
End Sub
Can someone please help to clear up the error in one of the above two
examples. Once I solve this I need to work out how to get it to open a
different word template depending on another field in the form.
Thanks for any assistance you may be able to provide.