|
code
newsgroups
|
|||||||||||||||||||||||
|
|||||||||||||||||||||||
Checkbox - how to clear without triggering click eventHello -
I have a form with a checkbox. I am trying to clear the form and included the code: If ckComplaint.Value = 1 Then ckComplaint.Value = 0 End If along with other code that clears textboxes, etc. The above statement is triggering the Click event of the checkbox instead of just changing the box to blank. How do I get around that? -- Sheldon
Show quote
Hide quote
"Sheldon" <Shel***@discussions.microsoft.com> wrote in message You set a flag and check in the click eventnews:015EF782-9369-4F66-B691-E43E624B2B79@microsoft.com... > Hello - > > I have a form with a checkbox. I am trying to clear the form and included > the code: > > If ckComplaint.Value = 1 Then > ckComplaint.Value = 0 > End If > > along with other code that clears textboxes, etc. The above statement is > triggering the Click event of the checkbox instead of just changing the > box > to blank. How do I get around that? private mbFromCode as boolean mbFromCode=True ckComplaint.Value = vbUnchecked ' use constant for readability mbFromCode = False Private Sub ckComplaint_Click() If Not mbFromCode Then ' user clicked end if end sub
Show quote
Hide quote
"Bob Butler" <noway@nospam.ever> wrote in message The Click event fires if Form_Load code assigns a value to check the box news:Ovm%23gPD9JHA.4976@TK2MSFTNGP04.phx.gbl... > > "Sheldon" <Shel***@discussions.microsoft.com> wrote in message > news:015EF782-9369-4F66-B691-E43E624B2B79@microsoft.com... >> Hello - >> >> I have a form with a checkbox. I am trying to clear the form and >> included >> the code: >> >> If ckComplaint.Value = 1 Then >> ckComplaint.Value = 0 >> End If >> >> along with other code that clears textboxes, etc. The above statement is >> triggering the Click event of the checkbox instead of just changing the >> box >> to blank. How do I get around that? > > You set a flag and check in the click event > > private mbFromCode as boolean > > mbFromCode=True > ckComplaint.Value = vbUnchecked ' use constant for readability > mbFromCode = False > > Private Sub ckComplaint_Click() > If Not mbFromCode Then > ' user clicked > end if > end sub > (like 1). It does not fire if you uncheck the box (with a 0), I assume because this does not change the state of the check box. I use a boolean flag whenever I only want a Click event Sub to run when the user initiates the event, and not when my code does. However, I wasn't aware of the vbUnchecked and vbChecked constants, which I like. Interesting that Intellisense doesn't suggest them. "Richard Mueller [MVP]" <rlmueller-nospam@ameritech.nospam.net> wrote in <cut>message news:%23i4PuaE9JHA.3544@TK2MSFTNGP04.phx.gbl... > The Click event fires if Form_Load code assigns a value to check the box Correct; if you check the box in design mode and then run the results would > (like 1). It does not fire if you uncheck the box (with a 0), I assume > because this does not change the state of the check box. be reversed. Click fires when the state changes. <cut> > However, I wasn't aware of the vbUnchecked and vbChecked constants, which If you look at the object browser the Value property is defined "As Integer" > I like. Interesting that Intellisense doesn't suggest them. so intellisense can't say anything about it. If it had been declared "As CheckBoxConstants" then it would show the options: vbChecked, vbUnchecked, vbGrayed "Bob Butler" <noway@nospam.ever> wrote in message I've always wondered why MS didn't make the CheckBox's Value property As news:%234Xq8OF9JHA.3752@TK2MSFTNGP05.phx.gbl... > >> However, I wasn't aware of the vbUnchecked and vbChecked constants, which >> I like. Interesting that Intellisense doesn't suggest them. > > If you look at the object browser the Value property is defined "As > Integer" so intellisense can't say anything about it. If it had been > declared "As CheckBoxConstants" then it would show the options: vbChecked, > vbUnchecked, vbGrayed CheckBoxConstants in order to provide Intellisense since there is that Enum type. Only 2 things I've been able to come up with (not that I've ever put a LOT of thought into this): 1. Compatibility....Enums are Long and they needed to keep the Value property an Integer. But I don't really know what compatibility issues that could have caused. 2. They simply overlooked it. But, it still could have been "fixed" anywhere from VB4 to VB6 and any service pack in between. Early on it bugged the bejeebers out of me because I could never remember the constants for some reason (dunno why as they're pretty straight-forward). -- Mike What confuses some is that the option button uses a boolean type
to determine whether it is selected or not while the checkboxes use a 0 or 1, not technically boolean. Saga Show quoteHide quote "MikeD" <nob***@nowhere.edu> wrote in message news:OHu7lEG9JHA.2120@TK2MSFTNGP02.phx.gbl... > > "Bob Butler" <noway@nospam.ever> wrote in message > news:%234Xq8OF9JHA.3752@TK2MSFTNGP05.phx.gbl... >> >>> However, I wasn't aware of the vbUnchecked and vbChecked constants, >>> which I like. Interesting that Intellisense doesn't suggest them. >> >> If you look at the object browser the Value property is defined "As >> Integer" so intellisense can't say anything about it. If it had been >> declared "As CheckBoxConstants" then it would show the options: >> vbChecked, vbUnchecked, vbGrayed > > > I've always wondered why MS didn't make the CheckBox's Value property As > CheckBoxConstants in order to provide Intellisense since there is that > Enum type. Only 2 things I've been able to come up with (not that I've > ever put a LOT of thought into this): > > 1. Compatibility....Enums are Long and they needed to keep the Value > property an Integer. But I don't really know what compatibility issues > that could have caused. > 2. They simply overlooked it. But, it still could have been "fixed" > anywhere from VB4 to VB6 and any service pack in between. > > Early on it bugged the bejeebers out of me because I could never remember > the constants for some reason (dunno why as they're pretty > straight-forward). > > -- > Mike > > "Saga" <antiSpam@nowhere.com> wrote in message news:%23KYNDJa9JHA.200@TK2MSFTNGP05.phx.gbl... That's because a checkbox is a tri-state...checked, unchecked, or grayed....another reason to use the constants instead of the > What confuses some is that the option button uses a boolean type > to determine whether it is selected or not while the checkboxes > use a 0 or 1, not technically boolean. Saga > literals 0, 1, or 2. -- Mike
Other interesting topics
Web Pages in a VB Window?
PowerBASIC String Memory Recovery Inno Setup and Dependencies Download multiple files concurrently using WinHttpRequest can i do this with real database, not just dataset The JET VBA File...Help Please! Proxy + ADO + VB6... Macro to Print Text to file in UTF-8 JPEG File Compression |
|||||||||||||||||||||||