#1   Report Post  
Posted to microsoft.public.excel.programming
external usenet poster
 
Posts: 37
Default Validation

Help for a form newbie.

I need to verify input to a text box in a form.
It must be exactly 6 characters.
First is always "p"
The next 5 are any number.

I know how to verify if it is all a number but not sure
how to do it for a combo of letter and numbers.

Any help would be appreciated. Sorry if this is a second
post. I posted yesterday but did not see it appear.

Thanks in advance
  #2   Report Post  
Posted to microsoft.public.excel.programming
external usenet poster
 
Posts: 5,441
Default Validation

Dave,

You could use the change event of the textbox. The example below if for
Testbox1.

You would also need to check the length of the Textbox1.Text prior to
accepting further processing, say when the OK button is clicked.

Private Sub CommandButton1_Click()
If Len(TextBox1.Text) < 6 Then Exit Sub
'Other code here

End Sub

HTH,
Bernie
MS Excel MVP

Private Sub TextBox1_Change()
Dim mytest As Double
If Len(TextBox1.Text) = 0 Then Exit Sub
If Len(TextBox1.Text) = 1 Then
If UCase(TextBox1.Text) = "P" Then
Exit Sub
Else
MsgBox "You have to start with a ""P"""
TextBox1.Text = ""
Exit Sub
End If
End If
If Len(TextBox1.Text) 6 Then
TextBox1.Text = Left(TextBox1.Text, 6)
MsgBox "That's long enough!"
Exit Sub
End If

On Error GoTo Bad

mytest = CDbl(Mid(TextBox1.Text, 2, 6))
Exit Sub
Bad:
MsgBox "You need to enter a P followed by 5 digits!"
TextBox1.Text = Left(TextBox1.Text, Len(TextBox1.Text) - 1)

End Sub

"Dave" wrote in message
...
Help for a form newbie.

I need to verify input to a text box in a form.
It must be exactly 6 characters.
First is always "p"
The next 5 are any number.

I know how to verify if it is all a number but not sure
how to do it for a combo of letter and numbers.

Any help would be appreciated. Sorry if this is a second
post. I posted yesterday but did not see it appear.

Thanks in advance



  #3   Report Post  
Posted to microsoft.public.excel.programming
external usenet poster
 
Posts: 37
Default Validation

Thanks very much Bernie, Works great!
-----Original Message-----
Dave,

You could use the change event of the textbox. The

example below if for
Testbox1.

You would also need to check the length of the

Textbox1.Text prior to
accepting further processing, say when the OK button is

clicked.

Private Sub CommandButton1_Click()
If Len(TextBox1.Text) < 6 Then Exit Sub
'Other code here

End Sub

HTH,
Bernie
MS Excel MVP

Private Sub TextBox1_Change()
Dim mytest As Double
If Len(TextBox1.Text) = 0 Then Exit Sub
If Len(TextBox1.Text) = 1 Then
If UCase(TextBox1.Text) = "P" Then
Exit Sub
Else
MsgBox "You have to start with a ""P"""
TextBox1.Text = ""
Exit Sub
End If
End If
If Len(TextBox1.Text) 6 Then
TextBox1.Text = Left(TextBox1.Text, 6)
MsgBox "That's long enough!"
Exit Sub
End If

On Error GoTo Bad

mytest = CDbl(Mid(TextBox1.Text, 2, 6))
Exit Sub
Bad:
MsgBox "You need to enter a P followed by 5 digits!"
TextBox1.Text = Left(TextBox1.Text, Len(TextBox1.Text) -

1)

End Sub

"Dave" wrote in

message
...
Help for a form newbie.

I need to verify input to a text box in a form.
It must be exactly 6 characters.
First is always "p"
The next 5 are any number.

I know how to verify if it is all a number but not sure
how to do it for a combo of letter and numbers.

Any help would be appreciated. Sorry if this is a second
post. I posted yesterday but did not see it appear.

Thanks in advance



.

Reply
Thread Tools Search this Thread
Search this Thread:

Advanced Search
Display Modes

Posting Rules

Smilies are On
[IMG] code is On
HTML code is Off
Trackbacks are On
Pingbacks are On
Refbacks are On


Similar Threads
Thread Thread Starter Forum Replies Last Post
data validation invalid in dynamic validation list ilia Excel Worksheet Functions 0 November 7th 06 12:54 PM
Data validation with validation lists and combo boxs Keith Excel Discussion (Misc queries) 1 October 12th 06 11:08 AM
Validation (Drop down list vs simple text length validation) Bob Phillips[_6_] Excel Programming 2 April 27th 04 07:47 PM
Validation (Drop down list vs simple text length validation) Jason Morin[_2_] Excel Programming 1 April 27th 04 04:56 PM
Validation (Drop down list vs simple text length validation) Pete McCosh Excel Programming 0 April 27th 04 03:49 PM


All times are GMT +1. The time now is 06:39 PM.

Powered by vBulletin® Copyright ©2000 - 2024, Jelsoft Enterprises Ltd.
Copyright ©2004-2024 ExcelBanter.
The comments are property of their posters.
 

About Us

"It's about Microsoft Excel"