Checkboxes (1 Viewer)

Gaux

New member
Local time
Yesterday, 16:12
Joined
May 1, 2014
Messages
8
I have 3 checkboxes on a form called report required, report received and form complete. I am trying to use the input from the first two checkboxes to determin if the third is visible or enabled. If a record needs a report but it has not yet been received i do not want the form complete ckeckbox to be enabled until the report received checkbox is completed. I have tried various ways to do this using if and Then etc and uses them on the after event of the first checkbox and on the forms current event but to no avail. I am new at this so any help would be appericated.
 

ypma

Registered User.
Local time
Today, 00:12
Joined
Apr 13, 2012
Messages
643
I maybe missing the point but, my understanding is that the only check box that requires code is check2 "report received".if that is the case could not you use the following:
#Private Sub Check2_Click()
If Me.Check2 = -1 Then
Me.Check3.enabled = True
Else
Me.Check3.enabled = False
me.check3 = 0 'in case checked in error
End If
End Sub#

You mentioned visible in your OP that could be included

I am not a programmer but use vb6 So hope this is of use to you
Regards Ypma
 

MarkK

bit cruncher
Local time
Yesterday, 16:12
Joined
Mar 17, 2004
Messages
8,180
This is two problems, 1) to create logic that enables--or not--the final checkbox, and 2) when to trigger the execution of that logic.

I would write a routine that performs the logic, and that receives as parameters the settings of the first two check boxes, so the signature of the routine will be . . .
Code:
Private Sub LastCheckboxEnabled(chkFirst as boolean, chkSecond as boolean)

Then, you need to run that routine in the Current event of the form, so when any record loads in the form, and then also when the user clicks either of the first two check boxes.

So the operation is performed in one place, but it can be triggered from multiple places.
 

ypma

Registered User.
Local time
Today, 00:12
Joined
Apr 13, 2012
Messages
643
Gaux

If you have solved your question please mark it as solved . Its very frustrating not to have any feed back , If the offered solution is not what you wanted please explain why, and then other suggestion can be considered.

Regards Ypma
 

Gaux

New member
Local time
Yesterday, 16:12
Joined
May 1, 2014
Messages
8
Yuma
Thanks for your reply I have not been able to try the the solutions offered yet as I have been away from work, I will be back at this shortly. With regards you thread it is not only check two that requires code, if check1 is ticked that a report is required then check three needs disabled until check 2 is ticked that the report has been received and then check 3 is enabled again. also check 2 should not be enabled unless check one is ticked, but check 3 should be able to be ticked as a report may not be required. This all needs to work on every record as each record may have a different combination.
 

ypma

Registered User.
Local time
Today, 00:12
Joined
Apr 13, 2012
Messages
643
GAUX

For some reason I thought you were using vb , I have had a go at your various combinations and can only come with, that you would need another check box for Report Not Required and then it seems to work..

#"Private Sub Form_Current()
If Me.chkReportRequired = 0 Then
Me.chkReportReceived.Enabled = False
Me.chkFormComplete.Enabled = False
Else
If Me.chkReportRequired = -1 And Me.chkReportReceived = 0 Then
Me.chkReportReceived.Enabled = True
Me.chkFormComplete.Enabled = False
End If
End If
If Me.chkReportNotRequired = -1 Then
Me.chkFormComplete.Enabled = True
Me.chkReportRequired = 0
Me.chkReportReceived = 0
Me.chkReportRequired.Enabled = False
Me.chkReportReceived.Enabled = False
End If
End Sub


Private Sub chkReportReceived_Click()
If Me.chkReportReceived = -1 Then
Me.chkFormComplete.Enabled = True
End If
End Sub
Private Sub chkReportRequired_Click()
If Me.chkReportRequired = -1 Then
Me.chkReportReceived.Enabled = True
End If
End Sub
Private Sub chkReportNotRequired_Click()
If Me.chkReportNotRequired = -1 Then
Me.chkFormComplete.Enabled = True
Me.chkReportRequired = 0
Me.chkReportReceived = 0
Me.chkReportRequired.Enabled = False
Me.chkReportReceived.Enabled = False
Else
Me.chkFormComplete.Enabled = False
Me.chkReportReceived.Enabled = False
Me.chkReportRequired.Enabled = True
End If
End Sub #"
Hope this makes sense , I could send you a sample in access if this is not clear , I have versions 2003 and 2010

Regards Ypma
 

Gaux

New member
Local time
Yesterday, 16:12
Joined
May 1, 2014
Messages
8
Thanks
I see what you mean about another check box , I will try this tomorrow and let you know how I get on.
 

MarkK

bit cruncher
Local time
Yesterday, 16:12
Joined
Mar 17, 2004
Messages
8,180
And my point is, separate the logic from the process that triggers the logic, and the whole thing gets way simpler . . .
Code:
Private Sub Form_Current()
    ResetForm
End Sub

Private Sub chkReportReceived_Click()
    ResetForm
End Sub
Private Sub chkReportRequired_Click()
    ResetForm
End Sub
Private Sub chkReportNotRequired_Click()
    ResetForm
End Sub

Sub ResetForm()
    If Me.chkReportRequired = 0 Then
        Me.chkReportReceived.Enabled = False
        Me.chkFormComplete.Enabled = False
    Else
        If Me.chkReportRequired = -1 And Me.chkReportReceived = 0 Then
            Me.chkReportReceived.Enabled = True
            Me.chkFormComplete.Enabled = False
        End If
    End If

    If Me.chkReportNotRequired = -1 Then
        Me.chkFormComplete.Enabled = True
        Me.chkReportRequired = 0
        Me.chkReportReceived = 0
        Me.chkReportRequired.Enabled = False
        Me.chkReportReceived.Enabled = False
    End If

End Sub
. . . and that is just a copy of Ypma's logic, and I haven't tested it.
 

Gaux

New member
Local time
Yesterday, 16:12
Joined
May 1, 2014
Messages
8
I have run this but it seems to blank the first three check boxes if i go back and enter a report received, So when a new record is entered it already has disabled the first three boxes thus not allowing you to continue. It may be something i am doing, at present i am running this in Access 2007 but it will be running on 2010 when finished
 

ypma

Registered User.
Local time
Today, 00:12
Joined
Apr 13, 2012
Messages
643
My error . providing you have a id field you could use the following at the start of the current event of the form
#Private Sub Form_Current()
If IsNull(ID) Then
Me.chkReportRequired.Enabled = True
Me.chkReportNotRequired.Enabled = True
Me.chkReportReceived.Enabled = True
Me.chkFormComplete.Enabled = True
Exit Sub
End If#
In addition to my early solution you could add in the # Private Sub chkReportReceived_Click()
Me.chkFormComplete.Enabled = False #

Let know how you get on
Regards Ypms
 

MarkK

bit cruncher
Local time
Yesterday, 16:12
Joined
Mar 17, 2004
Messages
8,180
Also, keep in mind that with boolean values you can directly assign the result of a boolean expression, so contrast this . . .
Code:
If IsNull(x) Then
    Me.chk.Enabled = True
Else
    Me.chk.Enabled = False
End If
. . . with a much shorter way of performing exactly the same amount of work . .
Code:
   Me.chk.Enabled = IsNull(x)
 

ypma

Registered User.
Local time
Today, 00:12
Joined
Apr 13, 2012
Messages
643
Also, keep in mind that with boolean values you can directly assign the result of a boolean expression, so contrast this . . .

Valued Point noted and appreciated, not being a programmer I have picked up many old ways of doing things .
Regards Ypma
 

MarkK

bit cruncher
Local time
Yesterday, 16:12
Joined
Mar 17, 2004
Messages
8,180
We're all always learning. Thanks for you contribution around here. :)
 

Gaux

New member
Local time
Yesterday, 16:12
Joined
May 1, 2014
Messages
8
My error . providing you have a id field you could use the following at the start of the current event of the form
#Private Sub Form_Current()
If IsNull(ID) Then
Me.chkReportRequired.Enabled = True
Me.chkReportNotRequired.Enabled = True
Me.chkReportReceived.Enabled = True
Me.chkFormComplete.Enabled = True
Exit Sub
End If#
In addition to my early solution you could add in the # Private Sub chkReportReceived_Click()
Me.chkFormComplete.Enabled = False #

Let know how you get on


Regards Ypms

Thanks this works well th k you for all your assistance
 

Gaux

New member
Local time
Yesterday, 16:12
Joined
May 1, 2014
Messages
8
Have got it working thanks for all your help
 

Gaux

New member
Local time
Yesterday, 16:12
Joined
May 1, 2014
Messages
8
Thanks for your help working at last
 

Users who are viewing this thread

Top Bottom