Results 1 to 3 of 3
  1. #1
    4 Star Lounger
    Join Date
    Apr 2001
    Posts
    482
    Thanks
    0
    Thanked 0 Times in 0 Posts

    Populating text box based on option button (Word 2000 VBA)

    <img src=/S/surrender.gif border=0 alt=surrender width=31 height=23> OK, I'm stumped. I've been spending an embarrasing number of hours trying to get around this problem. I have three option buttons on what I will call UserForm2. Depending on which option button is selected, different sample text should appear on UserForm1. Unfortunately, what appears in this text field is very random. I could cycle through the option buttons, displaying UserForm1 after selecting each one, and get different results each time.

    I have tried putting the code to populate the text box in the Click event of the option buttons (which is what I have in the attached example), and have put it in the initialize event of UserForm1, and have even tried putting it in both.

    I have tried populating the list box by explicitly defining the Text and/or Value property of the text box (which is what I have in the attached example), and have tried populating it with a variable. I have the same results each time. <img src=/S/brickwall.gif border=0 alt=brickwall width=30 height=15>

    I have added some labels to UserForm2 to make sure that the Boolean variables are being set properly. They serve no other purpose.

    PLEASE NOTE: The attached example is a crude recreation of a much larger project. I know there are probably a lot of things I could do to make it better, but it is just for the purpose of illustrating the issue mentioned above.

    To run the form, click RunForm. Choose an option button. Then click CommandButton1 to view the result in the text box. Clicking User Document should populate the text box with the text "Month YYYY". Clicking User Document option button should populate the text box with "Month DD, YYYY". Clicking the Technical Document option button should populate the text box with "month DD, YYYY".

    P.S. I use the DATE method to format user input based on a variable set from the option buttons. This picks up the variable value just fine and formats the text correctly every time. I just can't get the stinking sample text to show up properly. <img src=/S/bash.gif border=0 alt=bash width=35 height=39>

    I would be truly greatful for any help!!
    Troy
    Attached Files Attached Files

  2. #2
    Gold Lounger
    Join Date
    Feb 2001
    Location
    Dublin, Ireland, Republic of
    Posts
    2,697
    Thanks
    1
    Thanked 0 Times in 0 Posts

    Re: Populating text box based on option button (Word 2000 VBA)

    Troy,

    I think your main problem stems from the fact that your code displays UserForm1 before it actually assigns the value to the Textbox, so it is in fact returning th epreviuous selection. Try placing the UserForm1.Show as the last line in the UserForm2.CommandButton1_Click() event.

    I have not read all the code, but is it necessary to assign the state of the option buttons to variables. Try The following, which might get rid of the need of some variable assignments :<pre>Private Sub CommandButton1_Click()
    If <font color=red>obBusinessDocument</font color=red> = True Then
    UserForm1.tbDate.Text = "Month DD, YYYY"
    ElseIf <font color=red>obUserDocument</font color=red> = True Then
    UserForm1.tbDate.Text = "Month YYYY"
    ElseIf <font color=red>obTechnicalDocument</font color=red> = True Then
    UserForm1.tbDate.Text = "month DD, YYYY"
    End If
    <font color=red>UserForm1.Show</font color=red>
    End Sub</pre>

    That of course belongs in UserForm2. Changes highlighted in red.

    Hope it helps,

    Andrew C

  3. #3
    4 Star Lounger
    Join Date
    Apr 2001
    Posts
    482
    Thanks
    0
    Thanked 0 Times in 0 Posts

    Re: Populating text box based on option button (Word 2000 VBA)

    I can't believe it was that simple. Yes, moving the UserForm1.Show to the last step solved my problem.

    F.Y.I., the reason I was using variables is simply because they already existed and are set by the click event on the object buttons for other reasons within the larger application (which I did not include in the sample).

    Thanks so much for your help!!
    Troy <img src=/S/blush.gif border=0 alt=blush width=15 height=15>

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts
  •