I have multiple variable placeholders in a Word document that need to be replaced with variable information from an Access table. My Word document defines these variable placeholders with this syntax: "{mfld...}" The {mfld signifies the start of the variable placeholder, and the } signifies the end of the placeholder. I have done this type of thing many times in Access VBA using InStr, Left, Mid, and Right as necessary. But in Word, it (I think) would be best to use Selection... and/or Range... I've been doing a lot of reading on these two objects but just not getting the hang of it yet.
Here is what I'm trying to accomplish.
The characters between the "{mfld" and "}" make up the name of a field in a table of variable information found in MS Access. By getting that table field name, I can use a DLookUp in Access to get the data I need to put into the Word document. For me, that is the easy part. What I need is how to work with Range (or Selection) to get that variable name that is between the "{mfld" and "}".
So, here are the steps as I see them.
1. find "{mfld"
2. copy the variable name between {mfld and } into a variable within VBA.
For example, within the document I will have {mfldTenantNames}, and {mfldTenacyAddress}, and {mfldLandlordName}, etc. I want to put "TenantNames" into a VBA variable so I can use that with the DLookup operaton in Access. After I have the data from Access, I will do a .Find.Execute Replace:=wdReplaceAll to get the data into the Word document. Then I want to move to the next "{mfld...}"
Thanks!
ps: I do not want to use Word fields as that would be more difficult for my users to define these documents in the first place.
Here is what I'm trying to accomplish.
The characters between the "{mfld" and "}" make up the name of a field in a table of variable information found in MS Access. By getting that table field name, I can use a DLookUp in Access to get the data I need to put into the Word document. For me, that is the easy part. What I need is how to work with Range (or Selection) to get that variable name that is between the "{mfld" and "}".
So, here are the steps as I see them.
1. find "{mfld"
2. copy the variable name between {mfld and } into a variable within VBA.
For example, within the document I will have {mfldTenantNames}, and {mfldTenacyAddress}, and {mfldLandlordName}, etc. I want to put "TenantNames" into a VBA variable so I can use that with the DLookup operaton in Access. After I have the data from Access, I will do a .Find.Execute Replace:=wdReplaceAll to get the data into the Word document. Then I want to move to the next "{mfld...}"
Thanks!
ps: I do not want to use Word fields as that would be more difficult for my users to define these documents in the first place.