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 Chriss Miller on being selected by the Tek-Tips community for having the most helpful posts in the forums last week. Way to Go!

Text validation/Input mask help 3

Status
Not open for further replies.

mulligh

Technical User
May 8, 2001
97
US
I have a text field. What will be entered in this field is a series of letters (length varies) followed by a space and then followed by a series of numbers: e.g. NA 4555 or Jones 1234

I want to make sure that people always put a space between the series of letters and numbers. Since the length of these elements can vary, is there any way to do this?
 
Dear mullgih,
first do a trim to the value you fetch from the textboxand then
try the instr() function and check if " " is in your string.

oryou could use 2 textboxes : text1 for the number and text2 for the text and then concatenate them:
trim(text1.text) & " " & trim (text2.text)
you could then also check wether your first text is numeric or not with isnumeric(text1.text)

HTH

regards astrid
 
There are several ways of doing so, the more simplistic
being the following. Call your text box "txtDesc". In the "After Update" event select "Event Procedure".
Click on the ellipsis and type the following inside the
txtDesc_AfterUpdate() procedure.

If ValidText(txtDesc) = False Then
MsgBox "(Whatever you want your message to be)",vbExclamation
End If

After your procedure copy and paste the following function

Public Function ValidText(txtstr) As Boolean

ValidText = False

'Verify that the space exists to begin with.
If InStr(txtstr, " ") > 0 Then
'Verify that there is something in before the space is a number
If Len(Mid(txtstr, 1, InStr(txtstr, " ") - 1)) > 0 Then
'verify that whatever is typed after the space
If IsNumeric(Mid(txtstr, InStr(txtstr, " ") + 1, Len(txtstr))) Then
ValidText = True
End If

End If
End If

End Function

Let me know if that help! ;-)
 
Thanks for the replies. Ziwacky, this worked perfectly. Thanks so much for your help, I am very grateful.
 
Hi!

A couple of things about Ziwacky's reply:

Instead of the After Update event procedure use the Before Update event procedure with the following changes:

If ValidText(txtDesc.Text) = False Then
MsgBox "(Whatever you want your message to be)",vbExclamation
Cancel = -1
End If

This will automatically keep the user in the text box until they do it right and the wrong value will never be stored.

hth
Jeff Bridgham
bridgham@purdue.edu
 
Thanks jebry. That's a great idea and it worked perfectly. :-D
 
Status
Not open for further replies.

Part and Inventory Search

Sponsor

Back
Top