Tek-Tips is the largest IT community on the Internet today!

Members share and learn making Tek-Tips Forums the best source of peer-reviewed technical information on the Internet!

  • Congratulations IamaSherpa on being selected by the Tek-Tips community for having the most helpful posts in the forums last week. Way to Go!

Textbox validation inside a multipage 1

Status
Not open for further replies.

Jofx

Technical User
Jan 12, 2005
16
FR
HI,
I would like to validate a textbox value (numeric).
The textbox is inside the first page of a 2 pages multipage in a userform.
I did use a standard validation process in this case:
"beforeupdate" event on textbox which is calling a procedure

But, the point is: when you write a wrong value in the textbox and click immediatly on the second page of multipage, the textbox "beforeupdate" event doesn't start and the wrong value remains in the textbox without being validated.

Any solution ?
Thanks
Jofx
 
Private Sub TextBox1_BeforeUpdate(ByVal Cancel As MSForms.ReturnBoolean)
Cancel = Not IsNumeric(TextBox1.Text)
End Sub

With this if the text is not numeric you cannot change focus and go to an other control.


Hope this help
-bclt
 
Put the code for update in:

Private Sub TextBox1_AfterUpdate()
Sheet1.Cells(1, 1) = "The text is valid!"
End Sub
 
Thanks bclt, it's working fine
in addition, I'd like now 2 things:-
- add a message when textbox value is wrong
- user can leave the textbox with an empty value (and not necessary a numeric value, i.e 0)

Thanks a lot
Jofx
 
Private Sub TextBox1_BeforeUpdate(ByVal Cancel As MSForms.ReturnBoolean)
Cancel = Not (IsNumeric(TextBox1.Text) Or Trim(TextBox1.Text) = "")
If Cancel = True Then MsgBox "inValid!", vbCritical, "One Title here"
End Sub


:)
Do that fit you?
 
Something like this ?
Private Sub TextBox1_BeforeUpdate(ByVal Cancel As MSForms.ReturnBoolean)
If Len(TextBox1.Text) > 0 And (Not IsNumeric(TextBox1.Text)) Then
Cancel = True
MsgBox "textbox value is wrong"
End If
End Sub

Hope This Helps, PH.
Want to get great answers to your Tek-Tips questions? Have a look at FAQ219-2884 or FAQ181-2886
 
I come back to my first post:
My textbox is inside a multipage.
When I put a wrong value in the textbox1 and JUST AFTER click on a other page of the multipages container, the beforeupdate event is not started.

in that case, your first tip :
..............
Private Sub TextBox1_BeforeUpdate(ByVal Cancel As MSForms.ReturnBoolean)
Cancel = Not IsNumeric(TextBox1.Text)
End Sub
..............
works fine. the focus cannot be changed even you click on an other multipage page.

and your second tip :
................
Private Sub TextBox1_BeforeUpdate(ByVal Cancel As MSForms.ReturnBoolean)
Cancel = Not (IsNumeric(TextBox1.Text) Or Trim(TextBox1.Text) = "")
If Cancel = True Then MsgBox "inValid!", vbCritical, "One Title here"
End Sub
.................
doesn't work: After entering a bad value in textbox1, then click on any multipage page, no event occurs.

If you have any time, can you try this issue with a textbox inside a multipage ?
Jofx


 

Microsoft Support:

MultiPage control
Use a MultiPage control to work with a lot of information that can be sorted into several categories. A MultiPage control is made up of one or more Page objects that each contain a different set of controls. You can set the active page programmatically by setting the Value property of the MultiPage control.
 
Ouppps sorry i knew it with an other mane the multipage control.

This code works fine (to me). If you enter eg "3f" that is not blank and not numeric the Cancel will be true. As you click eg the page2 the textbox looses forus and the event BeforeUpdate fires. But as Cancel is true the focus goes back to the textbox1 which is at the page1.
 
You are right.
It works fine to me now

I just wanted to replace specific name "Textbox1" by a generic in the beforeupdate proc:
"Userform1.MultiPage1.Pages(Userform1.MultiPage1.Value).ActiveControl.name"

it didn't work because the (userform1.multipage.value)represents the current active page, not the one with the textbox error.
but thats Ok now, I found a workaround
Thanks again for your time
Jofx (alias frenchy)
 
Status
Not open for further replies.

Part and Inventory Search

Sponsor

Back
Top