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!

Checkbox Validation

Status
Not open for further replies.

enigma333

Programmer
Jul 3, 2001
42
CA
A checkbox does not update its datafield until after validation... is there a way to make it update as soon as the value changes ... e.g. on click. This will be done inside a custom control.

Thx
 
I believe the only way to do that is make the checkbox unbound and put your update code in the Click() event.

Hope that helps

~Mike
Any man willing to sacrifice liberty for security deserves neither liberty nor security.

-Ben Franklin
 
There must be some way to make the control validate on click ? or not?
 
Aha, I think I'm confused now. Do you want it to validate on click, or update on click? Here's what I noticed about the events a checkbox fires:

Validate - fires on mouse-down, checkbox value hasn't changed.
MouseDown - fires just after Validate, value hasn't changed
MouseUp - on mouse-up, value has changed
Click - on mouse-down/mouse-up, value has changed

As you can see, the Validate event fires before anything else, so in effect, it does validate on click. Your first post said that a checkbox doesn't update it's datafield until after validation, which makes sense since the Validate event won't see the new value because it hasn't actually changed yet. The first event fired that DOES see the change is the MouseUp event. If you need it to update as soon as the value changes, and the checkbox is not already bound to the field, the MouseUp is where to put the code. Is this what ur asking?

~Mike
Any man willing to sacrifice liberty for security deserves neither liberty nor security.

-Ben Franklin
 
Great that part helps ...
now the question is how do i make the validate event occur after the mouseup ...
i.e.
After MouseUp( after value has changed) i would like the control to be validated again ...

this will cause the bound field to be updated immediately after the value is changed ...

currently it doesn't change until the mousedown even occurs again or the control loses focus.

Perhaps i need to know how to cause the validate event ... when you call check1_validate that doesn't cause the validate event it simple runs the code in the validate sub.

In a nutshell i suppose i need a function that will cause the control to go through the validation process.
 
Let me see if I got this right... You need the value of the checkbox to change, run validation code, then commit to the DB, right? If so, you'll definately want to break your validation out into its own function instead of calling the validate event twice (once by VB and once by you), and unbind the control:

------------------------------------
Private Sub Check1_MouseUp(Button As Integer, Shift As Integer, X As Single, Y As Single)
'value has changed
If ValidateEntries = True Then
UpdateDatabase
Else
MsgBox DescriptiveErrorMessage
End If

End Sub

Private Sub ValidateEntries() As Boolean
If AllDataIsGood
ValidateEntries = True
Else
ValidateEntries = False
End If
End Sub

--------------------------------------

I suppose another way of doing this is assume the value of the checkbox in the validate event will be opposite what your validation code is expecting. In other words, if it's vbChecked and the user clicks it, Validate will show that it's still vbChecked, but treat it like it's vbUnchecked since that's what it's going to be anyway. The pitfall there, though is if the user clicks and drags off the control, having changed his/her mind about the action, it could cause problems. By default, VB would not change the checkbox's value, but your code will have validated based on an incorrect value for the checkbox.

Hope that's what ur looking for!

~Mike
Any man willing to sacrifice liberty for security deserves neither liberty nor security.

-Ben Franklin
 
Really i want to call the validate twice ... ideally prevent the first call and make it happen only once by my definition but if i could just make it happen then i'd be a happy kid.
Maybe not possible ...
Thanks for all the good input though
 
Status
Not open for further replies.

Part and Inventory Search

Sponsor

Back
Top