Disable control when another control has input

sstasiak

Registered User.
Local time
Today, 06:25
Joined
Feb 8, 2007
Messages
97
If I have an unbound text box and a checkbox in the same form, what code can I apply to the text box so that as soon as a character is entered, the checkbox is disabled?

On what action would I apply this code?
 
In the On Change event of the text box put:
Code:
If Len(Me.YourTextBoxNameHere)>0 Then
   Me.YourCheckBoxName.Enabled = False
Else
   Me.YourCheckBoxName.Enabled = True
End If
 
bob

I tried that and it doesn't seem to work. Not sure if it makes a difference, but I have a 'Password' input mask on the text box. Here's the code with my values plugged in:

Code:
Private Sub Text20_Change()
If Len(Me.Text20) > 0 Then
   Me.PassChange.Enabled = False
Else
   Me.PassChange.Enabled = True
End If
End Sub

I applied it to a different text field just to test it, and it works sometimes. It's strange because at times, the check box will disable, and other times it won't.
 
Last edited:
Try referencing the .Text property rather than the .Value property.
Code:
Private Sub Text20_Change()
If Len(Me.Text20[b].Text[/b]) > 0 Then
   Me.PassChange.Enabled = False
Else
   Me.PassChange.Enabled = True
End If
End Sub
 
Thanks RG

That works now.

Can you explain what the difference is between referencing .value and .text?

Also, if left off, is the default reference .value?

Thanks in advance
 
First of all, yes the default is .value

Text is what is in the text box currently and that's why it failed because if you start typing in the text box, technically it has no value until it updates and it doesn't update after each character.
Value is what it's value is after it's Update event (which doesn't really exist, you have BeforeUpdate and AfterUpdate) and in between it updates.
 
Alright Bob! You are now one of the moderators? Excellent!
 
For the record from VBA Help:
While the control has the focus, the Text property contains the text data currently in the control; the Value property contains the last saved data for the control. When you move the focus to another control, the control's data is updated, and the Value property is set to this new value. The Text property setting is then unavailable until the control gets the focus again. If you use the Save Record command on the Records menu to save the data in the control without moving the focus, the Text property and Value property settings will be the same.
Basically, as long as the user is still typing, the .Value property has not been updated yet but the .Text property contains what is showing in the control.
 
Thanks guys

You were all a great help. I have finished building my first DB, without any prior knowledge of Access. I have learned a lot.
 

Users who are viewing this thread

Back
Top Bottom