PDA

View Full Version : Live editing of OptionButton Caption on Userform



neilholmes
10-11-2011, 05:35 AM
Hi everyone,

One final piece of help on my project before its complete.

I have created a document that enables the user to create a report based on the importation of content selected via useforms. This is working great and I have had a LOAD of help from the forum (due to my lack of vb knowledge).

My final question is this.

Is it possible to edit the captions on OptionButtons attached to a userform while it is running ?

Simply I would like to enable a user (with administrator rights [or a password]) the option to click a button (on the open userform) that then enables the caption text to be edited.

The reason I want to do this, is to avoid the user having to go into vb editor to make the changes.

Is this possible ?

- Neil

gmaxey
10-11-2011, 06:12 AM
Neil,

Maybe not in the sense you are thinking about, but yes. If you provide text edit boxes to make the changes in then it is certainly possible. In the following code I have placed a textbox in a frame (one for each option button). When the user clicks the command button the frame (and its 3 text boxes become visible). Changes made in the text boxes are reflected in the option button captions.

rivate Sub UserForm_Initialize()
Frame1.Visible = False
CommandButton1.Caption = "Edit Captions"
End Sub
Private Sub CommandButton1_Click()
If CommandButton1.Caption = "Edit Captions" Then
If InputBox("Enter password", "Password") = "Neil" Then
Frame1.Visible = True
CommandButton1.Caption = "Save Changes"
TextBox1.Text = OptionButton1.Caption
TextBox2.Text = OptionButton2.Caption
TextBox3.Text = OptionButton3.Caption
End If

Else
Frame1.Visible = False
CommandButton1.Caption = "Edit Captions"
OptionButton1.Caption = TextBox1.Text
OptionButton2.Caption = TextBox2.Text
OptionButton3.Caption = TextBox3.Text
End If
End Sub

In actual practice you would probably want to adjust the size of your form to expand and contract to show the editing features.

neilholmes
10-11-2011, 06:22 AM
Greg... You are a genius !

Thanks yet again... This works perfectly.

- Neil

neilholmes
10-13-2011, 04:05 AM
Hi Greg,

Just noticed something with regards to the above... How do I save the changes to the template file ?

If the user (creating the report) makes changes to the caption on the OptionButtons I would like this to then take effect on the global template. Possibly with a warning message coming up ? "Are you sure you wish to save these changes?" when the user clicks CommandButton1 to save changes.

The template document will be held on a server for multiple user access.

Thanks

- Neil

gmaxey
10-13-2011, 07:01 AM
Neil,

Without a lot of thought (because I don't have time this morning) I think the easiest way may be to set document variables with the caption values that you assign. Then when the form is initialized set the intial captions using the variable values.

I hope that makes sense and I hope it works.