By using this site, you agree to our updated Privacy Policy and our Terms of Use. Manage your Cookies Settings.
426,122 Members | 921 Online
Bytes IT Community
+ Ask a Question
Need help? Post your question and get tips & solutions from a community of 426,122 IT Pros & Developers. It's quick & easy.

entry validation by the first letter

P: n/a
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
Share this Question
Share on Google+
3 Replies


P: n/a
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

P: n/a
-----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

P: n/a
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 discussion thread is closed

Replies have been disabled for this discussion.