Checkboxes and Queries

BCullenward

Registered User.
Local time
Today, 16:11
Joined
Jul 6, 2005
Messages
28
I have a checkbox that's bound to a recordset and am trying to find a way to disable a button if all records are checked. However, it appears that the sub must end before I can execute the code to get the correct results of what has been checked.

For example:
I have 4 records that have been checked and one that has not yet been checked. My button is enabled. I check the fifth record's checkbox. The button should now be disabled.

The Way It Currently Works:
I have 4 records that have been checked. I check the fifth one. The button is still enabled. I uncheck a box. The button disables. I uncheck another box. The button is enabled.

What is happening:
Since the events for the checkbox run in no logical order
(something like Mouse Up, Before Update, After Update, Click) in that order, I can not run my query to check if all checkboxes are checked then disable the button until after the click event.

Has anyone else experienced anything like this or know how to fix it?
 
Were have you placed the code, this could be where the problem is.
 
In the before update I had done my verifying whether the box should be checked or not (it was in the click event)
then I had my check to see if all records had been flagged after that in the click event.
 
Hrrmmm... I may have found a solution (for if anyone else runs across this problem).

I have my verifying everything in the before update.
in the click event I set the focus to a hidden text box (which is not bound and doesn't allow any input) and after setting the focus to that I do my check to see if everything has been flagged (still in the click event).

It looks something like this
Code:
Private Sub chkCompleted_BeforeUpdate(Cancel As Integer)
    Dim confirm As Integer
    If chkCompleted = True Then
        confirm = MsgBox("Are you sure everything has been received?", vbYesNo, "Confirm Complete")
        If confirm = vbNo Then
            chkCompleted.Value = 0
            Exit Sub
        Else
           'its been confirmed, do stuff
        End If
    Else
        confirm = MsgBox("Are you sure stuff is missing?", vbYesNo, "Confirm Missing")
        If confirm = vbNo Then
            chkCompleted.Value = 1
            Exit Sub
        Else
        'its undone.  To some other stuff
        End If
    End If
End Sub

Private Sub chkCompleted_Click()
    Me.Parent!txtHidden.SetFocus
    Dim rsME2 As New ADODB.Recordset
    Dim sqlME2 As String
    sqlME2 = "SELECT Fieldname FROM Table WHERE Completed = 0"
    rsME2.Open sqlME2, CurrentProject.Connection, adOpenForwardOnly, adLockReadOnly
    If rsME2.EOF Then
        Me.Parent!cmdButton.Enabled = False
    Else
        Me.Parent!cmdButton.Enabled = True
    End If
    rsME2.Close
    Set rsME2 = Nothing
    Me.Parent.reFresh
End Sub
 

Users who are viewing this thread

Back
Top Bottom