Tek-Tips is the largest IT community on the Internet today!

Members share and learn making Tek-Tips Forums the best source of peer-reviewed technical information on the Internet!

  • Congratulations John Tel on being selected by the Tek-Tips community for having the most helpful posts in the forums last week. Way to Go!

Need help with simple UserForm PLEASE! 2

Status
Not open for further replies.

joysong

Technical User
Nov 30, 2006
3
US
I am not a programmer. However, I am in the position of creating a word macro to be used by about 300 people across the state. I have 2 successfully functioning InputBoxes (where the user types in text, which is then placed in the Word document, followed by the end of the sentence when the window is closed.

I need a third which allows for a radio button (or similar) selection of *one* of three options to be placed in the document, with the final part of the statement added upon closure of the window.

I have copied what I have and pasted it below, and it actually works, believe it or not. The down side is it will keep entering the associated text as many times as you are willing to click the option. I just want to have only one choice and I don't know how to make a close button for the window or how to place it into the macro with the other InputBoxes to run it.

Thanks in advance for your help. If you want to see what it looks like, e-mail me and I will e-mail it to you.

THANK YOU! LCA [yinyang]
__________________________________________________________

Private Sub CheckBox1_Click()

Selection.TypeText Text:=" General District "
End Sub

Private Sub CheckBox2_Click()

Selection.TypeText Text:=" Circuit "

End Sub

Private Sub CheckBox3_Click()

Selection.TypeText Text:=" Juvenile and Domestic Relations "

End Sub


Private Sub CommandButton4_Click()
Selection.TypeText Text:= _
"Court, and has been mailed/forwarded to the attorney for the"
Selection.TypeText Text:=" Commonwealth pursuant to "
Selection.TypeText Text:="§19.2."

End Sub



Private Sub UserForm_Click()

End Sub

Private Sub UserForm_Initialize()

End Sub



 
ok, oops, you can't e-mail me, sorry. <blush> :-(
 

One easy way - after inserting the text, disable the checkboxes.
Code:
Private Sub CheckBox1_Click()
    Selection.TypeText Text:=" General District "
    Checkbox1.Enabled = False
    Checkbox2.Enabled = False
    Checkbox3.Enabled = False
End Sub
.. and do the same for each checkbox. If you had them in a Frame, you could just disable the Frame. If you used radio buttons instead, and had a separate button to press, you could (a) just have your code in one place and (b) give the users the option to change their choice before committing.

Enjoy,
Tony

--------------------------------------------------------------------------------------------
We want to help you; help us to do it by reading this: Before you ask a question.

Professional Office Developers Association
 
Replace the check boxes with option buttons and put them in a frame. With the option buttons in a frame they can only pick one. Add a button (CommandButton1) to submit the selection.

Code:
Private Sub CommandButton1_Click()

sOption As String

If OptionButton1.Value = True Then sOption = " General District"

If OptionButton2.Value = True Then sOption = " Circuit "

If OptionButton3.Value = True Then sOption = " Juvenile and Domestic Relations "

Selection.TypeText Text:=sOption

End Sub


 
ok guys, thanks so much, both of these things work... however, I want people to be able to change their choice, which won't be entered until they hit "close" or something.

the second thing is the suggestion: " Add a button (CommandButton1) to submit the selection." This I don't know how to do. I mean I know how to add a command button, I just don't know how to make it enter the choice then close the window.

I really appreciate the help, as I said I am not a programmer but a duffer and although I have figured out a lot, I don't understand it, I just know it mostly does what I want it to.

Thank You!!!
Linda Carol Adrienne [yin yang]
 
I want people to be able to change their choice, which won't be entered until they hit "close" or something.

That is the purpose of CommandButton1. You can rename it so makes sense, I usually use 'Submit'. Here is a bit more code:

Code:
Private Sub CommandButton1_Click()

Dim sOption As String ' temp value

' Assign the selected value to sOption
If OptionButton1.Value = True Then sOption = " General District"

If OptionButton2.Value = True Then sOption = " Circuit "

If OptionButton3.Value = True Then sOption = " Juvenile and Domestic Relations "

' Write sOption to a bookmark
ActiveDocument.Bookmarks("Test").Range = sOption

' Delete the bookmark
ActiveDocument.Bookmarks("Test").Delete

' Close the userform
Unload UserForm1

End Sub

Insert a bookmark (I inserted a bookmark and named it 'Test') in the document where you want the text to go.

The logic goes like this:

The user selects one of the option buttons, nothing happens yet. They can change their selection if they make a mistake. When they are satisfied with their selection they hit the Submit (CommandButton1) button and the above code is run. The code goes through all the option buttons and finds the one that is True. It then assigns the text string to sOption. The text is then written to the bookmark location, the bookmark is deleted, and the form is closed.
 
Status
Not open for further replies.

Part and Inventory Search

Sponsor

Back
Top