Results 1 to 7 of 7

Thread: Prevent code from executing

  1. #1

    Thread Starter
    Hyperactive Member Gimpster's Avatar
    Join Date
    Oct 1999
    Location
    Redmond, WA 98052
    Posts
    331

    Post

    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
    [email protected]
    ICQ# 47799046


  2. #2
    Serge's Avatar
    Join Date
    Feb 1999
    Location
    Scottsdale, Arizona, USA
    Posts
    2,744

    Post

    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.
    Code:
    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
    [email protected]
    ICQ#: 51055819


  3. #3

    Thread Starter
    Hyperactive Member Gimpster's Avatar
    Join Date
    Oct 1999
    Location
    Redmond, WA 98052
    Posts
    331

    Post

    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
    [email protected]
    ICQ# 47799046


  4. #4
    Guest

    Post

    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: [email protected]

  5. #5

    Thread Starter
    Hyperactive Member Gimpster's Avatar
    Join Date
    Oct 1999
    Location
    Redmond, WA 98052
    Posts
    331

    Post

    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
    [email protected]
    ICQ# 47799046


  6. #6
    Guru Aaron Young's Avatar
    Join Date
    Jun 1999
    Location
    Red Wing, MN, USA
    Posts
    2,177

    Post

    If you really wanted to you could setup a Private Boolean Variable to Indicate when you are making a Programmatic Change, ie.
    Code:
    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
    [email protected]
    [email protected]


  7. #7

    Thread Starter
    Hyperactive Member Gimpster's Avatar
    Join Date
    Oct 1999
    Location
    Redmond, WA 98052
    Posts
    331

    Post

    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

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts
  •  



Click Here to Expand Forum to Full Width