PDA

View Full Version : SOLVED: UserForm Text



Kindly_Kaela
12-14-2006, 12:40 PM
I'm writing a VBA/WORD macro. My program has 10 UserForms for the user to fill out. The data eventually populates a word document. I want the last form to summarize all the data the user inputted so the user can double check that he/she entered the information correctly.

I'm trying to use the command TextBox1.Text = variable. How do you get that command to activate automatically, without the user hitting a button? How do you get a command to execute as soon as a form loads?

Thank you in advance,
Kaela
:cloud9:

mdmackillop
12-14-2006, 04:58 PM
You can add initial values to the form using the Initialize event, and also call a sub
eg

Private Sub UserForm_Initialize()
Me.TextBox1.Text = "MD"
Call who
End Sub

Sub who()
MsgBox TextBox1.Text
End Sub


Not that I've ever used one, but you can create a multipage userform which might be neater than 10 separate forms, which would have the benefit that the user can go back, if necessary, to previously entered data.

fumei
12-19-2006, 08:33 AM
10 userforms! Yikes. Yes, a MultiPage would deinfitely be the way to go.

Yes, Malcolm is correct.
How do you get a command to execute as soon as a form loads?You get instructions to fire one a userform opening by putting code in the _Initialize event.

Kindly_Kaela
12-21-2006, 01:55 PM
Sounds great, but how do you do a multi-page?

lucas
12-21-2006, 05:38 PM
Kindly,
Just insert a new userform and from the toolbox where you get your controls select Multipage and drag it on to your new userform.

right click on the multipage control for options such as add page, rename, delete, etc.

Kindly_Kaela
12-22-2006, 07:29 AM
Thanks Steve. Does the user have to see the page tabs at the top? I'd like to just have a 'NEXT' and 'BACK' button on the bottom.

Also, I'm very new to VBA and just got the hang of opening and closing forms. What are some basic commands for a multi-page form?

Thanks!
Kaela

lucas
12-22-2006, 08:18 AM
Try this for navigation buttons. On the userform below the multipage control:

Private Sub BackButton_Click()
MultiPage1.Value = MultiPage1.Value - 1
UpdateControls
End Sub
Private Sub NextButton_Click()
MultiPage1.Value = MultiPage1.Value + 1
UpdateControls
End Sub


Not sure about tab visability....check the properties box or maybe someone that has more info will come by. I will take a look at it when I get a minute and let you know if I figure anything out. You can read lots about basic commands here in the forum. Just do searches. I know it takes time but that's often what I do to answer questions posted in the forum.

fumei
12-25-2006, 10:27 AM
I do not believe you can NOT have the Tabs. However, if you had 10 userforms, surely you can have titles for the Tab text?

I am attaching a sample document. It has a MultiPage, and a Validate button. The Validate button simply displays a message box with all the input values. There are textboxes, and comboboxes. ALL of the values (including any textboxes that are blank) are displayed.

The user can click Yes - in which case you add code to do whatever it is you are doing. Or, the user can click No - in which case they are returned to the userform.

For this demo, clicking yes displays a message saying everything is OK, and then unloads the userform.

You can show the userform by either the keyboard shortcut Alt-T, or clicking "Show Test Form" on the menu bar at the top.

Now...I don't know how many fields you are dealing with, but the key issue is what level of validation logic are you going to do? Right now, this sample demo ONLY works on the user clicking either Yes (the displayed values are OK), or No (the displayed values are not OK).

Let me warn you that validation logic is THE biggest aspect of using VBA userforms for information input. It can get very complex depending, again, on what level of validation you are trying to achieve.

Are you trying for bullet-proof error trapping, or basic error trapping (eg. no blank textboxes allowed)? By bullet-proof error trapping I mean say you have a textbox for "Name".

Is this for two names? One name? What if they put two names, but you really only want one - say Last Name? Do you want the first letter capitalized, and when you check to see if it is - do you change it, or hand that back to the user? Do you check each character to see if it is valid? What if the user typed in Petre Norton (assuming that should be Peter Norton)? What if the user typed in Peter5 Norton - they accidently hit the 5 key, just above the "r"? Does it matter? Are you going to check for it?

Again, let me warn you...REALLY validating user input against what you determine IS valid, is a major pain. It is fabulous when it is done, but getting there can be serious work.