Hello:
Been playing around for a bit using MS Access and Word 2000.
I have a nice nifty form that is designed to help my office staff open and make simple changes to a Word document that acts as a template.
The template is connected to a series of Access fields that are used as mail merge fields, and they work great, so no problems there.
But here's the thing:
I really would LIKE to have some built in statically positioned, yet changeable-in-content WORD fields in the template document file that I can modify through VBA code from ACCESS.
The fields I am proposing are nothing fancy, but would contain no more than a few words each at most, so it's not sentences or paras or anything like that.
The idea is, open the document and change the field content and then save/close it before merging. At least, that's the plan in theory...
What's frustrating - Bookmarks are not good for this sort of thing. They can't be changed or edited without disappearing from the document entirely, so no luck there.
Word Fields are not much better from the looks of it so far.
I've been having great difficulty trying to figure out how to get them to change or be modified once I've set them initially as DocVariables - I have one static DocVariable in my template that I've added in Word manually called "strB1", which I'm using as a basic proof-of-concept test.
So this isn't a big deal or anything.
I suppose I may just have to break down and simply add these elements into my mail merge query strings and add these field items as merge fields into my template, but that seems like a lot of unnecessary data handling and duplication for SUCH a simple thing in theory/concept.
But I've spent nearly a week on this "simple" thing and can't afford any more time, so any suggestions, if they are fairly straightforward and not too bothersome, would be greatly appreciated.
Maybe someone can see something obvious that I've missed. I don't want to reinvent the wheel here.
For those who want to take a stab at it, here's my code so far-this is all MS ACCESS 2000 Code and works fine in 2003.
NOTE: There are no NULL issues with the code. I've taken care of those things already..;-)
Thanks,
marcus101
Access/SQL/XML Developer
Ottawa, Canada
Been playing around for a bit using MS Access and Word 2000.
I have a nice nifty form that is designed to help my office staff open and make simple changes to a Word document that acts as a template.
The template is connected to a series of Access fields that are used as mail merge fields, and they work great, so no problems there.
But here's the thing:
I really would LIKE to have some built in statically positioned, yet changeable-in-content WORD fields in the template document file that I can modify through VBA code from ACCESS.
The fields I am proposing are nothing fancy, but would contain no more than a few words each at most, so it's not sentences or paras or anything like that.
The idea is, open the document and change the field content and then save/close it before merging. At least, that's the plan in theory...
What's frustrating - Bookmarks are not good for this sort of thing. They can't be changed or edited without disappearing from the document entirely, so no luck there.
Word Fields are not much better from the looks of it so far.
I've been having great difficulty trying to figure out how to get them to change or be modified once I've set them initially as DocVariables - I have one static DocVariable in my template that I've added in Word manually called "strB1", which I'm using as a basic proof-of-concept test.
So this isn't a big deal or anything.
I suppose I may just have to break down and simply add these elements into my mail merge query strings and add these field items as merge fields into my template, but that seems like a lot of unnecessary data handling and duplication for SUCH a simple thing in theory/concept.
But I've spent nearly a week on this "simple" thing and can't afford any more time, so any suggestions, if they are fairly straightforward and not too bothersome, would be greatly appreciated.
Maybe someone can see something obvious that I've missed. I don't want to reinvent the wheel here.
For those who want to take a stab at it, here's my code so far-this is all MS ACCESS 2000 Code and works fine in 2003.
NOTE: There are no NULL issues with the code. I've taken care of those things already..;-)
Code:
' Setup/open Word, no problems getting the file loaded..
Dim WordDoc As Object
Dim tempDoc As String
tempDoc = "C:\Templates\File1.doc"
Dim sigVal As String
sigVal = MyForm.NameValue.Value
Set WordDoc = CreateObject("Word.Application")
WordDoc.Documents.Open (tempDoc)
If Not WordDoc.Visible Then
WordDoc.Visible = True
End If
' This line works in that it sets up the initial value of
' the strB1 Word Field variable along with Fields.Update (below) but does not CHANGE it..
WordDoc.ActiveDocument.Variables("strB1") = sigVal
' I was hoping these two lines would take care of the changing part..no luck so far..
WordDoc.ActiveDocument.Fields.Item("DOCVARIABLE['strB1']") _
.Result = sigVal
WordDoc.ActiveDocument.Fields.Update
WordDoc.ActiveDocument.Save
' Set WordDoc = Nothing
Thanks,
marcus101
Access/SQL/XML Developer
Ottawa, Canada