Hello there anyone who can help...
I'm trying to open a query in ACCESS and replace bookmarks in a WORD.DOT (template). Please see the code below:
DoCmd.OpenQuery "qry1370frm4"
'Declare an instance of MS Word.
Dim wrd As New Word.Application
Set wrd = CreateObject("Word.application")
'Open the document template, make it visible
wrd.Documents.Add "h:\My Documents\ADatabase\RptTemplate.dot"
wrd.Visible = True
'Replace each bookmark with current data.
With wrd.ActiveDocument.Bookmarks
Dim BMRange As Range
'Identify current Bookmark range and insert text
Set BMRange = ActiveDocument.Bookmarks("dos").Range
BMRange.Text = [dos]
'Re-insert the bookmark
ActiveDocument.Bookmarks.Add "dos", BMRange
End With
DoCmd.Close , "qry1370frm4", acSaveNo
- My problem comes when trying to set BMRange.Text as the field name in the query. it doesn't want to transfer and gives me a "can't find project or library" error message.
Any ideas why? When i place it is quotes teh automations works wonderfully (it doesn't fill in the field but the code opens word and does what it should up to that point)
Any help would be WONDERFUL
Thanks
mcvayman
I'm trying to open a query in ACCESS and replace bookmarks in a WORD.DOT (template). Please see the code below:
DoCmd.OpenQuery "qry1370frm4"
'Declare an instance of MS Word.
Dim wrd As New Word.Application
Set wrd = CreateObject("Word.application")
'Open the document template, make it visible
wrd.Documents.Add "h:\My Documents\ADatabase\RptTemplate.dot"
wrd.Visible = True
'Replace each bookmark with current data.
With wrd.ActiveDocument.Bookmarks
Dim BMRange As Range
'Identify current Bookmark range and insert text
Set BMRange = ActiveDocument.Bookmarks("dos").Range
BMRange.Text = [dos]
'Re-insert the bookmark
ActiveDocument.Bookmarks.Add "dos", BMRange
End With
DoCmd.Close , "qry1370frm4", acSaveNo
- My problem comes when trying to set BMRange.Text as the field name in the query. it doesn't want to transfer and gives me a "can't find project or library" error message.
Any ideas why? When i place it is quotes teh automations works wonderfully (it doesn't fill in the field but the code opens word and does what it should up to that point)
Any help would be WONDERFUL
Thanks
mcvayman