473,385 Members | 1,863 Online
Bytes | Software Development & Data Engineering Community
Post Job

Home Posts Topics Members FAQ

Join Bytes to post your question to a community of 473,385 software developers and data experts.

entry validation by the first letter

Hi All,

How can I validate the entry in a text field depending on the first
letter of the string. I need to have a text box to acept 14 characters
if the first letter entered is M and 17 characters if the first letter
of the entry is A. I have been trying to do it for days. I also tried
to look for any other similar issues in the newsgroup, access help,
microsoft knowledge base...could not find any help. I'll appreciatte
any recommendation.
Nov 12 '05 #1
3 3288
TC
Put something like this in the BeforeUpdate event of the textbox:

(untested)

dim s as string, n as integer
s = nz (screen.activecontrol, "")
n = len (s)
select case left$ (s, 1)
case "M": if n <= 14 then exit sub
case "A": if n <= 17 then exit sub
end select
msgbox "invalid!"
cancel = true
end select

HTH,
TC
"pilar" <ca***********@hotmail.com> wrote in message
news:6b**************************@posting.google.c om...
Hi All,

How can I validate the entry in a text field depending on the first
letter of the string. I need to have a text box to acept 14 characters
if the first letter entered is M and 17 characters if the first letter
of the entry is A. I have been trying to do it for days. I also tried
to look for any other similar issues in the newsgroup, access help,
microsoft knowledge base...could not find any help. I'll appreciatte
any recommendation.

Nov 12 '05 #2
-----BEGIN PGP SIGNED MESSAGE-----
Hash: SHA1

You'll have to use the TextBox's BeforeUpdate event to validate the
data.

Private Sub txtMyText_BeforeUpdate(Cancel As Integer)

Dim strTxt As String
Dim strMsg As String

If Not IsNull(Me!txtMyText) Then

strTxt = Trim$(Me!txtMyText)

Select Case Left$(strTxt, 1)

Case "M"
If Len(strTxt) <> 14 Then
strMsg = "The data must have 14 characters"
End If

Case "A"
If Len(strTxt) <> 17 Then
strMsg = "The data must have 17 characters"
End If

Case Else
strMsg = "The data must start with an ""M"" and have " & _
"14 characters " & _
"or, start with an ""A"" and have 17 characters"
End Select

If Len(strMsg) > 0 Then
MsgBox "Invalid Data@" & strMsg & "@", vbCritical
Cancel = True
End If

End If

End Sub
MGFoster:::mgf
Oakland, CA (USA)

-----BEGIN PGP SIGNATURE-----
Version: PGP for Personal Privacy 5.0
Charset: noconv

iQA/AwUBP6B9tYechKqOuFEgEQLzzgCgnErkf2QKhux6WPKAng35qT giiogAoKGL
XTC/4CpqbawRxlFEAGfckcV8
=47Av
-----END PGP SIGNATURE-----

pilar wrote:
Hi All,

How can I validate the entry in a text field depending on the first
letter of the string. I need to have a text box to acept 14 characters
if the first letter entered is M and 17 characters if the first letter
of the entry is A. I have been trying to do it for days. I also tried
to look for any other similar issues in the newsgroup, access help,
microsoft knowledge base...could not find any help. I'll appreciatte
any recommendation.


Nov 12 '05 #3
MGFoster <me@privacy.com> wrote in message news:<N4*****************@newsread4.news.pas.earth link.net>...
-----BEGIN PGP SIGNED MESSAGE-----
Hash: SHA1

You'll have to use the TextBox's BeforeUpdate event to validate the
data.

Private Sub txtMyText_BeforeUpdate(Cancel As Integer)

Dim strTxt As String
Dim strMsg As String

If Not IsNull(Me!txtMyText) Then

strTxt = Trim$(Me!txtMyText)

Select Case Left$(strTxt, 1)

Case "M"
If Len(strTxt) <> 14 Then
strMsg = "The data must have 14 characters"
End If

Case "A"
If Len(strTxt) <> 17 Then
strMsg = "The data must have 17 characters"
End If

Case Else
strMsg = "The data must start with an ""M"" and have " & _
"14 characters " & _
"or, start with an ""A"" and have 17 characters"
End Select

If Len(strMsg) > 0 Then
MsgBox "Invalid Data@" & strMsg & "@", vbCritical
Cancel = True
End If

End If

End Sub
MGFoster:::mgf
Oakland, CA (USA)

-----BEGIN PGP SIGNATURE-----
Version: PGP for Personal Privacy 5.0
Charset: noconv

iQA/AwUBP6B9tYechKqOuFEgEQLzzgCgnErkf2QKhux6WPKAng35qT giiogAoKGL
XTC/4CpqbawRxlFEAGfckcV8
=47Av
-----END PGP SIGNATURE-----

pilar wrote:
Hi All,

How can I validate the entry in a text field depending on the first
letter of the string. I need to have a text box to acept 14 characters
if the first letter entered is M and 17 characters if the first letter
of the entry is A. I have been trying to do it for days. I also tried
to look for any other similar issues in the newsgroup, access help,
microsoft knowledge base...could not find any help. I'll appreciatte
any recommendation.


1000 Thank you guys! I was able to make it works.
Nov 12 '05 #4

This thread has been closed and replies have been disabled. Please start a new discussion.

Similar topics

6
by: Drew | last post by:
I've already created a simple method of ensuring that all form feilds are filled out before the form is submitted to an ASP page for records to be added to the data base. (Sorry about the...
7
by: Tom | last post by:
How do I set up the following Validation Rules in a table: 1. Two chars - both must be digits(0-9) 2. Three characters - first character must be a letter 3. 6 characters - all must be...
2
by: Coleen | last post by:
I can't remember the correct way to write a custom regular expression validator, and the help file for VB.net is not terribly helpful...it does not give any real world examples. I've got the main...
20
by: hippomedon | last post by:
Hello everyone, I'm looking for some advice on whether I should break the normalization rule. Normally, I would not consider it, but this seems to be a special case. I have created an...
0
by: taylorcarr | last post by:
A Canon printer is a smart device known for being advanced, efficient, and reliable. It is designed for home, office, and hybrid workspace use and can also be used for a variety of purposes. However,...
0
by: Charles Arthur | last post by:
How do i turn on java script on a villaon, callus and itel keypad mobile phone
0
by: emmanuelkatto | last post by:
Hi All, I am Emmanuel katto from Uganda. I want to ask what challenges you've faced while migrating a website to cloud. Please let me know. Thanks! Emmanuel
0
BarryA
by: BarryA | last post by:
What are the essential steps and strategies outlined in the Data Structures and Algorithms (DSA) roadmap for aspiring data scientists? How can individuals effectively utilize this roadmap to progress...
1
by: nemocccc | last post by:
hello, everyone, I want to develop a software for my android phone for daily needs, any suggestions?
1
by: Sonnysonu | last post by:
This is the data of csv file 1 2 3 1 2 3 1 2 3 1 2 3 2 3 2 3 3 the lengths should be different i have to store the data by column-wise with in the specific length. suppose the i have to...
0
by: Hystou | last post by:
There are some requirements for setting up RAID: 1. The motherboard and BIOS support RAID configuration. 2. The motherboard has 2 or more available SATA protocol SSD/HDD slots (including MSATA, M.2...
0
marktang
by: marktang | last post by:
ONU (Optical Network Unit) is one of the key components for providing high-speed Internet services. Its primary function is to act as an endpoint device located at the user's premises. However,...
0
Oralloy
by: Oralloy | last post by:
Hello folks, I am unable to find appropriate documentation on the type promotion of bit-fields when using the generalised comparison operator "<=>". The problem is that using the GNU compilers,...

By using Bytes.com and it's services, you agree to our Privacy Policy and Terms of Use.

To disable or enable advertisements and analytics tracking please visit the manage ads & tracking page.