PDA

View Full Version : Can Docvariable Fields have a space in their name?



NanaHawk
05-24-2011, 11:02 AM
Hi Everyone,
first post from me so please be gentle :-)

I have several hundred documents that contain DOCVARIABLE fields and I want a user to be able to select their chosen and document and then for VBA code to iterate through it and provide prompts for the associated value.

All works well until the field & variable have a space in their name and then the variable is created but the update does not work.

Is it possible to utilise fields with a space in the name or not?

The code below shows the kind of code I'm using:
For Each myfield In ActiveDocument.Fields

myFieldName = Trim(Mid(myfield.Code, 14, 99))
ActiveDocument.Variables(myFieldName).Value = "Update to something new"

Next myfield

ActiveDocument.Fields.Update

Any and all input would be appreciated.

Frosty
05-24-2011, 12:15 PM
It is possible to have a document variable with a space in the name.
However, that line where you are getting the field name, but trying to extract the docvariable field may be causing you an issue.

Perhaps you should step through the code, and see whether myFieldName is actually referencing a document variable which exists in the document?

NanaHawk
05-24-2011, 12:33 PM
It is possible to have a document variable with a space in the name.
However, that line where you are getting the field name, but trying to extract the docvariable field may be causing you an issue.

Perhaps you should step through the code, and see whether myFieldName is actually referencing a document variable which exists in the document?

NanaHawk
05-24-2011, 12:38 PM
Thanks for your thoughts Frosty.

I am sure that the process works when there is no space in the name and the variable updated looks to have the same name as the field I want to be updated. I will check again but are you suggesting that it might be the wrong approach?
NanaHawk

Frosty
05-24-2011, 12:42 PM
Well, you are using a Trim function... Which removes space characters. I don't think it is coincidence that the function is breaking on doc variables which contain spaces when you are trying to identify those doc variables after running a function which removes spaces from a string.

However, without seeing the real before and after (the field.code you are extracting the variable from), I can only give hints