Jump to content

Auto-replace the text form field value


Recommended Posts

Posted

Hi there,

I have a question regarding forms in MS Word. This is what I would like to do:

I want to replace the value of the text in a text form field depending on what value is entered. I wrote a macro to run on 'entry' of the text form field, as follows:

Sub ChooseReason()

Dim Message, Title, Default, ReasonChosen

ReasonChosen = 0 ' Initialize variable.

Message = "Enter the reason number (1 through 3)" ' Set prompt.

Title = "InputBox Demo" ' Set title.

Default = "0" ' Set default.

' Displaying the message, title, and default value in INPUTBOX.

ReasonChosen = InputBox(Message, Title, Default)

Select Case ReasonChosen ' Evaluate choice.

Case 1 ' 1st choice.

Set TextReason.Text = "Choice 1"

Case 2 ' 1st choice.

TextReason.Text "Choice 2"

Case 3 ' 1st choice.

TextReason.Text "Choice 3"

End Select

End Sub

The text in red is where I am trying to assign the form's text value. The text form has been bookmarked as 'TextReason'.

The initial problem is due to the drop-down form field items being "too short" for the values that I want to enter. The value of the first drop-down field would be the reason the user chooses the values of the second drop-down field, but it's not wide enough. So I thought that the text form field could be used as the size can be unlimited.

If anyone has encountered this or has any idea how to fix this, please help!

Thanks!!

Jo


Posted

1. I'm not sure why you're using a macro in the first place?

2. When I make form field entries, I first have a blank one that is as wide as I want the drop-down to appear. Just use spaces to create the first one. (I actually create it last, then move it up to the first position.)

I see. Maybe you want a conditional drop-down?

Try this knowledgebase entry by fumei:

http://vbaexpress.com/kb/getarticle.php?kb_id=5

Posted

Hi!!

Thanks for the link. I will check it out.

The reason that I am using a macro is because the DROPDOWN form field text maximum length is 50 characters and the TEXT form field text maximum length is unlimited. So I thought that I'd use the macro to auto-fill the text form field, depending on what is chosen in the drop down field.

Anyways, thanks again... I haven't had a chance to test the macro from the link yet, but hopefully it give me an idea on how to solve this.

J

Posted

Okay. I gotcha. And a few quick comments...

IF you are using a DOT file, you can create autotext entries for your 50+ text lines. Then run macros that insert the autotext. That way, if your text changes, you can just recreate the autotext instead of modifying the VBA.

http://www.officearticles.com/word/using_a...rosoft_word.htm

Maybe something like this will help?

http://visualbasic.about.com/library/weekly/aa021503e.htm

(sorry about the popup)

Create an account or sign in to comment

You need to be a member in order to leave a comment

Create an account

Sign up for a new account in our community. It's easy!

Register a new account

Sign in

Already have an account? Sign in here.

Sign In Now
  • Recently Browsing   0 members

    • No registered users viewing this page.
×
×
  • Create New...