PDA

View Full Version : Creating Userform Instructions



Killer Bud
05-27-2010, 06:39 PM
What I would like is to create a set of instructions that will teach the user how to use the userform if they choose to do so. I'm not really concerned that all of the comboboxes and textboxes are visible as my code will not allow them to enter anything until it's done in sequence anyways ie; thickness then material then qty etc.

So, the 1st msgbox pops up as soon as userform1 opens and asks if you would like to learn how to use the calculator....yes = choose your material ( which is combobox 2 ), no = userform1.show ( this is as far as I can get )

Once combobox2 shows a material then a msgbox pops up to then choose your thickness which is combobox3

Once combobox3 has a thickness then.... blah blah blah ......you get the picture

Here is what I have so far....but now I'm stumped as I don't know how to track the event changes for my comboboxes.



Private Sub Workbook_Open()
Userform1.Show

If MsgBox("Would you like to learn how to use the gasket calculator", vbYesNo) = vbYes Then
MsgBox " Ok, first you must choose your material from the drop down box located at the top left of this program"

Else
Userform1.Show
Exit Sub
End If
End Sub


Any help is greatly appreciated

Shred Dude
05-27-2010, 07:27 PM
You'll want to use one or more of the events associated with your comboboxes.

Try these in your Userform's code to get a feel for what happens when you change values in your comboboxes.

Private Sub ComboBox1_AfterUpdate()
MsgBox "After Update Event fired"
End Sub

Private Sub ComboBox1_Change()
MsgBox "change event fired"
End Sub


You may want to consider a public boolean variable in the code you already have to capture whether or not the user wants to see these message boxes and then add a check for that variables value in the combobox event you decide to use to determine whether or not to display the tutorial information.

If the information needed to be conveyed is concise enough you may be able to use the ControlTipText property of the combobox to contain some text that will appear when the user's mouse is over the combobox.

Hope that gets you going int he right direction. Good luck with it.

Killer Bud
05-27-2010, 08:12 PM
Thanks for the reply....that gets me started, somewhat.
I'm fairly new to VBA and I'm having a real tough time here.

"a public boolean variable in the code you already have to capture whether or not the user wants to see these message boxes and then add a check for that variables value in the combobox event you decide to use to determine whether or not to display the tutorial information. "

this is exactly what I want to do, but I don't know how to go about doing so.
I only want these message boxes to pop up if the user chooses to proceed with the tutorial.


Private Sub ComboBox1_AfterUpdate()
MsgBox "After Update Event fired"
End Sub

This works great, but I only want it to work when "yes" is clicked for the tutorial. Basically I'm asking to be spoon fed a bit here, lol.

Thanks for your help

mikerickson
05-27-2010, 11:20 PM
The attached uses a label instead of repeated message boxes.

in a userform's code module
Option Explicit

Dim ShowInstructions As Boolean

Private Sub UserForm_Initialize()
Rem these can be set at design time
TextBox2.ControlTipText = "Enter Name"
TextBox3.ControlTipText = "Enter Address"
TextBox4.ControlTipText = "Enter City,State,Zip"

Rem begin run time code
ShowInstructions = (MsgBox("Do you want instructions?", vbYesNo) = vbYes)
Label1.Visible = ShowInstructions

Rem code for hide instructions button
With butHideInstruction
.Visible = ShowInstructions

.Caption = "Hide Instructions": Rem design time
.TakeFocusOnClick = False: Rem design time
End With
End Sub

Sub moveLabel()
With ActiveControl
Label1.Width = 500
Label1.Left = .Left + .Width
Label1.Top = .Top + .Height
Label1.Caption = .ControlTipText
Label1.AutoSize = True
End With
End Sub

Private Sub TextBox2_Enter()
Call moveLabel
End Sub

Private Sub TextBox3_Enter()
Call moveLabel
End Sub

Private Sub TextBox4_Enter()
Call moveLabel
End Sub

Private Sub butHideInstruction_Click()
ShowInstructions = False
Label1.Visible = ShowInstructions
butHideInstruction.Visible = ShowInstructions
End Sub

Private Sub butClose_Click()
Unload Me
End Sub

Killer Bud
05-28-2010, 07:43 AM
Thanks for the code mikerickson. I entered it and changed code to suit my comboboxes and text boxes, but I'm getting an error here:



Rem code For hide instructions button
With butHideInstructions
.Visible = "ShowInstructions"

.Caption = "Hide Instructions": Rem design time
.TakeFocusOnClick = False: Rem design time

It is highlighting "butHideInstructions" beside With and giving me an error of Variable Not Defined...?? What am I missing here? I like these labels, I would like to get this to work.

mikerickson
05-28-2010, 07:47 AM
butHideInstructions is a command button, not a variable. If you add a command button to the UF (and give it that name) that should fix your problem.

Killer Bud
05-28-2010, 07:56 AM
Thanks, I named the command button incorrectly, that works perfect now.
Thanks for your help, this is what I needed. One more question, how would I go about hiding the instructions automatically when the user clicks on " No " after being asked "Do you want Instructions".....?

mikerickson
05-28-2010, 11:42 AM
In the posted workbook, a MsgBox "Instructions Y/n?" box is called by the Userform Intialize event.

If the user clicks Yes, the Label's visiblity is set to True, and it moves (and changes what it says) depending on which control has the focus.

If the user clicks No, its visibility is set to False, and it still moves around, but can't be seen.

If the user clicks Yes on the opening MsgBox, the HideInstructions button will allow the user to set the Label's visibilty to False when they tire of seeing the instructions. (The visiblity of that button is controled by the same variable as the visibility of the Label.)

This approach isn't a "training program", but rather an enhancement of ToolTip capabilities.