How to read ASK filed from VB

G

Glenn

Anyone know how to grab the data that a user has entered via an
ASK field.

Thanks much!
 
J

Jay Freedman

Hi, Glenn,

The ASK field contains a bookmark name that identifies the content of
the field. To get this in VB, assuming you've set the object objWdDoc
to point to the document, use something like this:

myString = objWdDoc.Bookmarks("bkmk1").Range.Text

where you replace "bkmk1" with the name you used in the ASK field,
keeping the quotes.
 
G

Glenn

Thanks Jay - Works like a champ! It does seem that any
Carriage Return or Newlines are captured by this as a message
box shows the text and a square. Is this what's happening?

Glenn
 
J

Jay Freedman

Hi, Glenn,

For reasons that are probably Lost in the Mists of Time (TM), a newline in
an ASK field is represented by ASCII 11 (the VBA constant vbVerticalTab) but
in a message box or in an ordinary paragraph of a document it's an ASCII 13
(or vbCr). The message box shows the vbVerticalTab as a square.

To convert for display, throw this line into your code between retrieving
the ASK field contents and displaying the message box:

myString = Replace(myString, vbVerticalTab, vbCr)

This assumes you're using Word 2000 or later; for Word 97 you need to write
your own Replace function, using a "For index" loop to step Mid(myString,
index, 1) through all the characters in myString.
 

Ask a Question

Want to reply to this thread or ask your own question?

You'll need to choose a username for the site, which only take a couple of moments. After that, you can post your question and our members will help you out.

Ask a Question

Top