VBA-Referenceing a Text Field in Active Document

C

critter

I created a Command Button in a form to send an email from Visual Basic by
following the instructions found here. http://support.microsoft.com/kb/161833
I want to use this to send a short "Order Notice" message to people. I need
to have the Message.Text to only show a unique order name and number for each
message sent.
How can I have the data from a specific Text Form Field on my form
automatically fill in the Message.Text field of my VBA Send Email button?
 
J

Jay Freedman

critter said:
I created a Command Button in a form to send an email from Visual
Basic by following the instructions found here.
http://support.microsoft.com/kb/161833 I want to use this to send a
short "Order Notice" message to people. I need to have the
Message.Text to only show a unique order name and number for each
message sent.
How can I have the data from a specific Text Form Field on my form
automatically fill in the Message.Text field of my VBA Send Email
button?

Every form field has a "bookmark name". By default for a text form field
it's "Text1", "Text2", etc. but you can change it in the form field's
Properties dialog -- it's a good idea to name each field according to its
purpose, like "OrderName" and "OrderNumber". So I'll assume from here on
that you have named those fields.

Then in the macro, replace the line

objMessage.Text = "This is the message text."

with something like this (you can change the text in quotes to suit your
requirements):

objMessage.Text = "Order Name: " & _
ActiveDocument.FormFields("OrderName").Result & _
vbCr & "Order Number: " & _
ActiveDocument.FormFields("OrderNumber").Result

The vbCr represents a carriage return, so the message text will be on two
lines. The underscores at the ends of the first three lines are continuation
characters; each one must have a space before it.

--
Regards,
Jay Freedman
Microsoft Word MVP
Email cannot be acknowledged; please post all follow-ups to the newsgroup so
all may benefit.
 
C

critter

Thanks Jay! I knew it was relatively simple with referencing the document
and the field but the actual coding of it had me lost.
 

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