PDA

View Full Version : userform review function



ramasterre
05-22-2008, 02:04 PM
Can someone provide an example of how to code a userform to check your answers before moving to the next multipage? I have a form with multipages that uses static back and next buttons to navigate (they are located on the userform not the multipage itself). And I want to be able to ensure that a user answers all the questions on a given page before they move on to the next page. Ideally this would be done by either clicking next and a macro would run and tell you if there are questions left to be answered or the next button would simply be deactivated until you finish all the questions.

The userform uses comboboxes, textboxes, and checkboxes. There are 8 pages in the multipage. Some items are conditional and will not need to be answered, i.e. if the answer to question two is Yes (combobox) then question 2a (textbox) must have text in it.

Any ideas or snippets of code would be really helpful, I'd like to make it as concise and bug free as possible :)

ramasterre
05-27-2008, 07:06 AM
I was able to pull together some code for this which I have also posted on Mr Excel.com. If any one can help out that would be great!


I am trying to build a macro that checks a given set of objects on my userform each time I change the page. I'm having trouble with my if...then statement to get the macro to show an error message when the user has not filled in an object on the page. Can someone help with the below code. So far its still 'in progress' but I'm focusing on getting the first case to work correctly. I need to say if the textbox isnt blank and the combobox isnt blank then move on to the next page but if either is blank then show the msgbox.

Private Sub MultiPage1_Exit(ByVal Cancel As MSForms.ReturnBoolean)
Dim i As Long

With MultiPage1
'For i = 0 To 5
If .Value = i Then

Select Case i

Case 0
If Not TextBox1.Value = "" Then
If Not ComboBox1.Text = "" Then
CommandButton1.Enabled = True
.Value = .Value + 1
MsgBox "You are on page 2"
Else:
MsgBox "Please answer all questions before continuing"
CommandButton1.Enabled = False

End If
Else: MsgBox "Please answer all questions before continuing"
CommandButton1.Enabled = False
End If

Case 1
MsgBox "You are on page 2"
Case 2
MsgBox "You are on page 3"
Case 3
MsgBox "You are on page 4"
Case 4
MsgBox "You are on page 5"
Case 5
MsgBox "You are on page 6"

End Select
End If
'Next i
End With
End Sub

R1C1
05-27-2008, 10:53 AM
Sub CommandButton1_Click
'
If TextBox1.Text = "" Then
Call MsgBox("Please answer the question in TextBox1.", vbExclamation, "Missing entry!") 'Change to suit.
Me.TextBox1.SetFocus
Exit Sub
End If
If ComboBox1.Text = "" Then
Call MsgBox("Please answer the question in ComboBox1.", vbExclamation, "Missing entry!")
Me.ComboBox1.Setfocus
Exit Sub
End If
'
'Code to retrieve next page here.
'
End Sub

Alan