Click to See Complete Forum and Search --> : Prevent code from executing
Gimpster
Dec 29th, 1999, 04:53 AM
I have some code in the text1_Change()Event and I want to be able to change the text (with code of course) without the text1_Change()Event code executing, is there any way I can send something like a Cancel message to the code script to keep it from firing?
------------------
Ryan
cornelsen@hotmail.com
ICQ (http://www.ICQ.com)# 47799046
Serge
Dec 29th, 1999, 09:43 AM
There are no arguments in the Change event, but you can use KeyPress event instead to check if correct information is being entered, and if not, then restrict the user from typing in the textbox.
Private Sub Text1_KeyPress(KeyAscii As Integer)
If KeyAscii <> 65 Then 'if it's not letter A
KeyAscii = 0
End If
End Sub
------------------
Serge
Software Developer
Access8484@aol.com
ICQ#: 51055819 (http://www.icq.com/51055819)
Gimpster
Dec 30th, 1999, 01:18 AM
No, that won't work Serge, I need to actually keep the code from firing, but if there's no way to keep that from happening then I guess I'll just have to figure out some other way around it. Thanks, though.
------------------
Ryan
cornelsen@hotmail.com
ICQ (http://www.ICQ.com)# 47799046
use the REM or ' to comment it out (if thats what you mean)
or just put the words: Exit Sub
at the top of the event, then none of the below code will work
------------------
Wossname,
Email me: wossnamex@talk21.com :)
Gimpster
Dec 30th, 1999, 01:58 AM
No, wossname, that's not what I need. I want the code to execute when the user changes the text box, but I do not want the code to execute when I change the text box programatically.
------------------
Ryan
cornelsen@hotmail.com
ICQ (http://www.ICQ.com)# 47799046
Aaron Young
Dec 30th, 1999, 02:00 AM
If you really wanted to you could setup a Private Boolean Variable to Indicate when you are making a Programmatic Change, ie.
Private bProgrammatic As Boolean
Private Sub Text1_Change()
If bProgrammatic Then Exit Sub
'Do Whatever for the Change Event
End Sub
Private Sub Command1_Click()
bProgrammatic = True
'Change the Text without Triggering the Change Event Code
Text1 = "Changed Text"
bProgrammatic = False
End Sub
------------------
Aaron Young
Analyst Programmer
aarony@redwingsoftware.com
ajyoung@pressenter.com
Gimpster
Dec 30th, 1999, 03:21 AM
Thank you! Thank you! Thank you! Aaron, you are the king! I had done that same thing in other parts of this program, but for some reason it didn't even occur to me to do that here. Thank you so much.
------------------
Ryan
vbforums.com
Copyright Internet.com Inc., All Rights Reserved.