Disable control OnClick of Checkbox

Melody

Registered User.
Local time
Today, 11:37
Joined
Aug 11, 2000
Messages
47
I have a checkbox (LocationDataCheck), and a text control (LocationDataEntered). When LocationDataCheck is checked, I want LocationDataEntered to be disabled. I've put the following code into the OnClick of LocationDataCheck:

Private Sub LocationDataCheck_AfterUpdate()
If Me.[LocationDataCheck] = -1 Then
Me.[LocationDataEntered].Enabled = True
Else
Me.[LocationDataEntered].Enabled = False
End If
End Sub

I'm getting the error message "Method compile error". . .??
 
Use the expression builder to build references to controls.
 
You don't need brackets around the textbox names when using Me. your code would be better used on the form's current event in the after update event of LocationDataCheck
add Form_Current
 
RICH & LLK - Thanks for your replies. I put the following code:

Private Sub Form_Current()
Private Sub LocationDataCheck_AfterUpdate()
If Me.LocationDataCheck = -1 Then
Me.LocationDataEntered.Enabled = True
Else
Me.LocationDataEntered.Enabled = False
End If
End Sub

in my form code, and now when I click on the form, nothing happens. ??
 
O.K. - I just got it to work. I switched my True and False statements, and it's fine now. Thanks!!
 
O.K. - This is working, but when I close and go back in, it's not saving it. (When I click the checkbox, it grays out the other control, but when I exit and go back in, the control is no longer grayed out, just the box is still checked.) Here's my code that's in the checkbox:

Private Sub UsernameDataCheck_BeforeUpdate(Cancel As Integer)
If Me.UsernameDataCheck = -1 Then
Me.UsernameDataEntered.Enabled = False
Else
Me.UsernameDataEntered.Enabled = True
End If
End Sub

Anyone know what I'm doing wrong??
 
Code should be
Private Sub Form_Current()

If Me.LocationDataCheck = -1 Then
Me.LocationDataEntered.Enabled = True
Else
Me.LocationDataEntered.Enabled = False
End If
End Sub

And
Private Sub LocationDataCheck_AfterUpdate()
Form_Current
End Sub
Two separate procedures, change true false parts to get working correctly.
 
RICH - Thanks for the suggestion. I tried it, and now I have a different problem - Now it's saving the control as grayed out, but it's not saving the check in the check box. I put this code:

Private Sub Form_Current()
If Me.LocationDataCheck = -1 Then
Me.LocationDataEntered.Enabled = True
Else
Me.LocationDataEntered.Enabled = False
End If
End Sub

in the On Current of my form, and this code:

Private Sub LocationDataCheck_AfterUpdate()
Form_Current
End Sub

in the After Update of my LocationDataCheck box. ??

Thanks again!
 
O.K. - I think I got it to work again - We'll see! I added this code to the On Current in the Form:

Private Sub Form_Current()
If Me.LocationDataCheck = -1 Then
Me.LocationDataEntered.Enabled = True
Else
Me.LocationDataEntered.Enabled = False
End If

If Me.LocationDataCheck = -1 Then
Me.LocationDataEntered.Enabled = False
Else
Me.LocationDataEntered.Enabled = True
End If

It looks like that is making it save both the grayed out control and the check in the checkbox.

Thanks again!!
 

Users who are viewing this thread

Back
Top Bottom