Detecting a Character

P

Peter Marshall

I'm looking for a simple way to check that the text entered into a text box
contains a slash at the end. I'm assuming VBA that executes On_Exit.
 
T

Tom van Stiphout

On Mon, 8 Mar 2010 08:30:18 -0500, "Peter Marshall"

if right$(Me.myTextBox,1) = "/" then
'yes it does
else
'no it doesn't
end if

-Tom.
Microsoft Access MVP
 
J

Jon Lewis

Private Sub Text1_Exit(Cancel As Integer)
If Not Right(Me.Text1, 1) = "/" Then
Cancel = True
MsgBox "No '/'", vbExclamation
End If
End Sub
 
S

Stefan Hoffmann

hi Peter,

I'm looking for a simple way to check that the text entered into a text box
contains a slash at the end. I'm assuming VBA that executes On_Exit.
You may use a input mask or use this in your event:

Const COLOR_LIGHTBLUE As Long = 15713933
Const COLOR_WHITE As Long = 16777215

Dim length As Long

length = Len(Trim(Nz(txtYourControl.Value, "")))
If (length > 0) And _
(Mid(txtYourControl.Value, length, 1) <> "-") Then
txtYourControl.BackColor = COLOR_LIGHTBLUE
Else
txtYourControl.BackColor = COLOR_WHITE
End If

btw, I would use the On Change event.


mfG
--> stefan <--
 
S

Stefan Hoffmann

hi Stefan,

Const COLOR_LIGHTBLUE As Long = 15713933
Const COLOR_WHITE As Long = 16777215

Dim length As Long

length = Len(Trim(Nz(txtYourControl.Value, "")))
If (length > 0) And _
(Mid(txtYourControl.Value, length, 1) <> "-") Then
txtYourControl.BackColor = COLOR_LIGHTBLUE
Else
txtYourControl.BackColor = COLOR_WHITE
End If

btw, I would use the On Change event.
In this case you must use txtYourControl.Text instead of
txtYourControl.Value,


mfG
--> stefan <--
 

Ask a Question

Want to reply to this thread or ask your own question?

You'll need to choose a username for the site, which only take a couple of moments. After that, you can post your question and our members will help you out.

Ask a Question

Top