Solved Enable disable button in a form based on a value of a text

Leo_Polla_Psemata

Registered User.
Local time
Today, 14:48
Joined
Mar 24, 2014
Messages
364
Hi there
I want to Enable or dis-enable a button based on the value of a text which is in the same form, i have typed the below however I am not sure where should i paste these five lines

Code:
If COUNAL.Value <> "" Then
    CommandButton2.Enabled = False
Else
    CommandButton2.Enabled = True
End If


 
Note that if you have a boolean value A, and you need to set another boolean value B that varies directly with A, you don't need an If block. Rather, you can set B directly from A, for example...
Code:
Me.cmdButton.Enabled = Me.txtValue & "" = ""
In a single line of code, the button is enabled if the textbox is null or zero length, AND the button is disabled if there is data in the control. If you like leaner code, this might make sense for you going forward.
Code:
If IsTrue = True Then
    Result = True
Else
    Result = False
End If
...can be replaced with...
Code:
Result = IsTrue
More of the same pattern...
Code:
If IsTrue = False Then
    Result = True
Else
    Result = False
End If
...can be replaced with...
Code:
Result = Not IsTrue
 
Hi there
When I used a control in the form like below, the enable/diasable function didn't work, when i changed the control with dlookup, it worked. What a crazy strange world we are living in...
=[Onesubform].[Form]![Onecontrol]
 
You need to post your code including the header so we can see what event and control it is in. dLookup() doesn't seem to make sense in this context.
Hi,
on my form, there is a button that runs an append query. Then, my table is updated.
The hazard is that i may click button for a second time and duplicate the records in the table.
To avoid this, i have added a text box on my form that counts the records in that table.
If text box is >1 then button is disabled, else, button = enabled.
To count the records i can use in this text box the
1. Dlookup function , or
2. count the subform records , =[Onesubform].[Form]![Onecontrol]

In both cases 1 or 2 , the text box outlines the correct number of records. say 59, which is >1 and therefore btn should turn to disable
HOWEVER in option 2, the update button doesn't turn to disable. It works only in option one , only by using dlookup

 

Users who are viewing this thread

Back
Top Bottom