PDA

View Full Version : Solved: Mutipage Case



slamet Harto
09-16-2008, 11:34 PM
Hi there,

I'm using multipage in a userform to entry new data. however, I have a problem by clik-ing Ok button with leaving blank in firstname box.

the problem is why the userform is unload eventhough I've been trapped with setfocus. Also, the data is write into a sheet.

Please find the attached for your refference.

Highly appreciate your suggestion. Thanks & Rgds,
Harto

Bob Phillips
09-17-2008, 01:31 AM
You need to exit the sub after encountering the error.



Private Sub OKButton_Click()
Dim NRowBaru As Integer

If TextBox2.Text = "" Then
MsgBox "please enter first name!"
TextBox2.SetFocus
Exit Sub
End If
If ComboBox1.Value = "" Then
MsgBox "please enter tittle!"
ComboBox1.SetFocus
Exit Sub
End If

With Sheets(1)
NRowBaru = WorksheetFunction.CountA(.Range("B:B")) + 4

If ComboBox3.Value = "" Then
MsgBox "Please Enter Type of this request! ", vbInformation, "Error message"
ComboBox3.SetFocus
'End If
ElseIf ComboBox3.Value = "BOTH" Then
.Cells(NRowBaru, 1).Value = "AAA"
.Cells(NRowBaru, 2).Value = ComboBox1.Value
.Cells(NRowBaru, 3).Value = TextBox2.Text
.Cells(NRowBaru, 1).Value = TextBox3.Text
NRowBaru = NRowBaru + 1
.Cells(NRowBaru, 1).Value = "BBB"
.Cells(NRowBaru, 2).Value = ComboBox1.Value
.Cells(NRowBaru, 3).Value = TextBox2.Text
.Cells(NRowBaru, 1).Value = TextBox3.Text
Else
.Cells(NRowBaru, 1).Value = ComboBox3.Value
.Cells(NRowBaru, 2).Value = ComboBox1.Value
.Cells(NRowBaru, 3).Value = TextBox2.Text
.Cells(NRowBaru, 1).Value = TextBox3.Text
End If

Call tosetfocus
End With

Range("A4").Select
Unload Me
End Sub

slamet Harto
09-17-2008, 01:40 AM
Hi Bob,

Brilliant! I'm glad to know you.
Have a nice day.

Best, Harto