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

If Statement; depending on value turn off other functions 1

Status
Not open for further replies.

rsch

Technical User
Mar 9, 2004
18
0
0
US
I have an IF statement that validates that only text is in a text box. For reference, here is the code:

Private Sub txtTicker_KeyPress(KeyAscii As Integer)
If KeyAscii >= 48 And KeyAscii <= 57 Then
MsgBox ("You entered " & "'" & txtTicker & "'" & ". A Ticker cannot contain numbers.")
Me.txtTicker = Null
Else
Exit Sub
End If
End Sub


If there is an erro , then I need to ignore my BeforeUpdate and AfterUpdate codes. Is there a way to do this from within the IF statement?
 
Try this:
Private Sub txtTicker_KeyPress(KeyAscii As Integer)
If KeyAscii >= 48 And KeyAscii <= 57 Then
MsgBox ("You entered " & "'" & txtTicker & "'" & ". A Ticker cannot contain numbers.")
Me.txtTicker = Null
docmd.cancelevent

End If
End Sub

I can't test it right now so let me know if it works.

HTH,
Eric
 
Wonderful. Thank you! Exactly what I needed.

In case anyone is interested, I modified my code slightly. Here if the final version:
If KeyAscii >= 48 And KeyAscii <= 57 Then
MsgBox ("A Ticker cannot contain numbers.")
DoCmd.CancelEvent
Me.txtTicker.Value = Null
End If
End Sub


 
Status
Not open for further replies.

Part and Inventory Search

Sponsor

Back
Top