MsgBox for beginners - Help please!

K

kastnna

I am new to VB and am having a little trouble. I want to write the
script so that a msgbox will open that ask a YesNo question. Clicking
yes will produce one answer in "textfield9" and clicking no will
produce a different answer in the same text field.

Thanks in advance
 
G

Greg

I am assuming that textfield9 is a formfield bookmark name.n Try
something like:

Sub ScratchMacro()
If MsgBox("Do you like beer?", vbYesNo, "Question") = vbYes Then
ActiveDocument.FormFields("textField9").Result = "Have one on me."
Else
ActiveDocument.FormFields("textField9").Result = "Ok, I'll have one
myself."
End If
End Sub
 
C

Charles Kenyon

Try writing some code and if it doesn't work, post it here and someone will
help you with it.
http://word.mvps.org/FAQs/MacrosVBA/VBABasicsIn15Mins.htm

In vba help, review the Input Box. (A Message Box doesn't collect
information from the user, just provides it to the user.)

Unless you want the user to be able to change it in the document, you
probably want to set a bookmark for your location in the document, and when
running your procedure unprotect the document, insert your information in
the bookmark, reprotect the document without resetting fields and then
continue. http://word.mvps.org/FAQs/MacrosVBA/InsertingTextAtBookmark.htm
In talking about protecting and unprotecting the document, I am assuming
that this is a document protected for forms - because of your field name.
This is what Word calls an "online form." Check this in help. For more about
online forms, follow the links at
http://addbalance.com/word/wordwebresources.htm#Forms or
http://word.mvps.org/FAQs/Customization/FillinTheBlanks.htm especially Dian
Chapman's series of articles. You may also want to look at
http://www.word.mvps.org/FAQs/TblsFldsFms/LinesInForms.htm.

Finally, rather than an input box (which calls for a text answer) you may
want a UserForm on which you can put checkboxes or drop-down menus. It is
well worth your time to learn to use UserForms because they are very
powerful and flexible.
http://word.mvps.org/FAQs/Userforms/CreateAUserForm.htm Ms. Chapman's later
articles discuss these as well.
--
Charles Kenyon

Word New User FAQ & Web Directory: http://addbalance.com/word

Intermediate User's Guide to Microsoft Word (supplemented version of
Microsoft's Legal Users' Guide) http://addbalance.com/usersguide


--------- --------- --------- --------- --------- ---------
This message is posted to a newsgroup. Please post replies
and questions to the newsgroup so that others can learn
from my ignorance and your wisdom.
 

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