Problem disabling controls based on the selection of a checked box

dafne

Registered User.
Local time
Today, 07:44
Joined
Apr 1, 2017
Messages
41
Hello,
I want to disable some combos and checkboxes whenever my first checkbox (NP_clausal) is selected. I've placed the code below in the After Update event of the NP_clausal checkbox and it works. I tried to paste it in the On Current event of the Form so that whenever I go back to the records I've already analyzed, it remembers that the controls are supposed to be disabled if NP_clausal is checked - this method worked when I tried to disable other controls based on the selection of a combo box, but it doesn't work here, and I don't know what to do anymore :banghead:. Can you help me?
Here's the code:
Code:
' Disable semantic features of NP if NP_clausal is True
If Me.checkNP_clausal.Value = "-1" Then
Me.cboNP_number.Enabled = False
Me.checkNP_animate.Enabled = False
Me.checkNP_referential_relation_obvious = False
Me.checkNP_active.Enabled = False
Me.checkNP_definite.Enabled = False
Me.cboNP_specificity.Enabled = False
Me.cboNP_collectiveness.Enabled = False
Me.cboNP_concreteness.Enabled = False
Me.cboVERB_agreement_NP.Enabled = False
Else
Me.cboNP_number.Enabled = True
Me.checkNP_animate.Enabled = True
Me.checkNP_referential_relation_obvious = True
Me.checkNP_active.Enabled = True
Me.checkNP_definite.Enabled = True
Me.cboNP_specificity.Enabled = True
Me.cboNP_collectiveness.Enabled = True
Me.cboNP_concreteness.Enabled = True
Me.cboVERB_agreement_NP.Enabled = True
End If
Thanks in advance!
Dafne
 
Do you really need quotes surrounding "-1"??
 
Both post moderated, now approved.
 
Do you really need quotes surrounding "-1"??
Hello. I'm new at this, so I'm learning on the go and by myself. I took off the quotes and nothing changed. I'd tried TRUE (without the quotes) before and it hadn't worked either. Again, the original code (with "-1") worked in the After Update event of my checkbox, but not on the On Current event of the form: in other words, it does what I want if I click on the checkbox, but whenever I come back to a record where that control has already been checked, the form "doesn't remember" that the other controls have to stay blocked.
 
Hi dafne,

In your line
Code:
If Me.checkNP_clausal.Value = "-1" Then

you don't need ".Value", nor the quote marks. Try changing the line to:

Code:
If Me.checkNP_clausal = True Then

That should work ok. The ".Value" property is different and explained in a Microsoft article - just google "Value Property".
 
For oncurrent to work checkNP_clausal needs to be bound to the table.

You missed an .enabled and are setting the value.
Me.checkNP_referential_relation_obvious.enabled = False

Enabled is true or false, a simple switch. You don't need an if
Code:
dim b as boolean
b=not checkNP_clausal

cboNP_number.Enabled = b
checkNP_animate.Enabled = b
checkNP_referential_relation_obvious.Enabled = b
checkNP_active.Enabled = b
checkNP_definite.Enabled = b
cboNP_specificity.Enabled = b
cboNP_collectiveness.Enabled = b
cboNP_concreteness.Enabled = b
cboVERB_agreet_NP.Enabled = b
 
Or another way of doing this with far less typing is to make use of the controls' Tag property.

Set all the controls you want to enable / disable with your checkbox to have the same Tag value e.g. NP

Then just write this in place of your long list of controls

Code:
If Me.checkNP_clausal.Value =True Then
	EnableControls False, "NP"
Else
	EnableControls True, "NP"
End If

The code for the EnableControls sub is:

Code:
Private Sub EnableControls(State As Boolean, Tg1 As String, Optional Tg2 As String, Optional Tg3 As String, _
        Optional Tg4 As String, Optional Tg5 As String, Optional Tg6 As String)

On Error GoTo Err_Handler

    'set controls to locked or not according to the control tag value
    For Each ctrl In Me.Controls
        Select Case ctrl.ControlType
        
        Case acLabel, acImage, acLine, acRectangle, acPageBreak
            'no code here - these can't be disabled
        Case Else
            If ctrl.Tag = Tg1 Or ctrl.Tag = Tg2 Or ctrl.Tag = Tg3 Or ctrl.Tag = Tg4 _
                    Or ctrl.Tag = Tg5 Or ctrl.Tag = Tg6 Then ctrl.Enabled = State
        End Select
        
    Next ctrl
  
Exit_Handler:
    Exit Sub

Err_Handler:
    MsgBox "Error " & Err.Number & " " & Err.Description
    Resume Exit_Handler
    
End Sub

Any number of controls can be given the same Tag value
As written the code allows up to 6 different tag values to be updated at the same time

e.g. EnableControls False, "A","B","D","G", "X","T"

I have similar code for ShowControls / LockControls

I have just uploaded a sample database showing these in use:
https://www.access-programmers.co.uk/forums/showthread.php?t=293439
 
For oncurrent to work checkNP_clausal needs to be bound to the table.

You missed an .enabled and are setting the value.
Me.checkNP_referential_relation_obvious.enabled = False

Enabled is true or false, a simple switch. You don't need an if
Code:
dim b as boolean
b=not checkNP_clausal

cboNP_number.Enabled = b
checkNP_animate.Enabled = b
checkNP_referential_relation_obvious.Enabled = b
checkNP_active.Enabled = b
checkNP_definite.Enabled = b
cboNP_specificity.Enabled = b
cboNP_collectiveness.Enabled = b
cboNP_concreteness.Enabled = b
cboVERB_agreet_NP.Enabled = b
Hi! I tried that, but I keep getting the error "Invalid use of Null". Any ideas?
 
Hi dafne,

In your line
Code:
If Me.checkNP_clausal.Value = "-1" Then

you don't need ".Value", nor the quote marks. Try changing the line to:

Code:
If Me.checkNP_clausal = True Then

That should work ok. The ".Value" property is different and explained in a Microsoft article - just google "Value Property".

That was actually my first try, but I kept getting all kinds of errors (maybe some interference from the rest of my code?). The "value" alternative was the only one that kind of worked - except in the On Current event of the form.
 
On Current is not working

Is the Form_Current not firing? Or is it that it fires but does wrong things? What specifically do you mean by "not working." (That is a catch-all answer, and it catches too much for us to start guessing.)
 
What datatype is checkNP_clausal?

see attached

View attachment 66068
Thank you for this. I'm starting to think there might be a conflict somewhere in my code. I'm a newbie, so that's possible. For instance, I've successfully disabled ALL NP... controls when cboNP_presence is NO:
Code:
' Disable options if there is NO NP
If Me.cboNP_presence.Column(0) = "2" Then
Me.cboVERB_agreement_NP.Enabled = False
Me.cboNP_position.Enabled = False
Me.checkNP_clausal.Enabled = False
Me.cboNP_function.Enabled = False
Me.cboNP_role.Enabled = False
Me.cboNP_number.Enabled = False
Me.checkNP_animate.Enabled = False
Me.checkNP_active.Enabled = False
Me.checkNP_definite.Enabled = False
Me.cboNP_specificity.Enabled = False
Me.cboNP_collectiveness.Enabled = False
Me.cboNP_concreteness.Enabled = False
Me.checkNP_topicalized.Enabled = False
Me.checkNP_coreference_se.Enabled = False
Me.cboNP_case.Enabled = False
Else
Me.cboVERB_agreement_NP.Enabled = True
Me.cboNP_position.Enabled = True
Me.checkNP_clausal.Enabled = True
Me.cboNP_function.Enabled = True
Me.cboNP_role.Enabled = True
Me.cboNP_number.Enabled = True
Me.checkNP_animate.Enabled = True
Me.checkNP_active.Enabled = True
Me.checkNP_definite.Enabled = True
Me.cboNP_specificity.Enabled = True
Me.cboNP_collectiveness.Enabled = True
Me.cboNP_concreteness.Enabled = True
Me.checkNP_topicalized.Enabled = True
Me.checkNP_coreference_se.Enabled = True
Me.cboNP_case.Enabled = True
End If

Edit: oh, yes, forgot to answer your question: checkNP_clausal is a simple checkbox (true or false). Is this what you meant?
 
Is the Form_Current not firing? Or is it that it fires but does wrong things? What specifically do you mean by "not working." (That is a catch-all answer, and it catches too much for us to start guessing.)
Hello! Form_Current is not firing. I managed to disable some controls based on the selection of a combo box and Form_Current worked. I'm trying to do the same thing, but based on the selection of a checkbox instead.

Once again, I'd like to thank all of you for taking time to answer my question! :)
 
Hi
You've spent ages on the other approaches unsuccessfully, despite expert assistance.

Suggest you try the EnableControls code I posted in #7 - it should work!
 

Users who are viewing this thread

Back
Top Bottom