Tek-Tips is the largest IT community on the Internet today!

Members share and learn making Tek-Tips Forums the best source of peer-reviewed technical information on the Internet!

  • Congratulations strongm on being selected by the Tek-Tips community for having the most helpful posts in the forums last week. Way to Go!

Disabling Control On Click of Checkbox

Status
Not open for further replies.

MelF

Technical User
Oct 26, 2000
81
US
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". . .??
 
The code itself looks good, but the timing of it may be off. Try using the BeforeUpdate event and see what happens.
 
OMEGA - Thanks for the response. Someone suggested that I take the brackets off the field names, so now I have this code:

Private Sub LocationDataCheck_BeforeUpdate(Cancel As Integer)
If Me.LocationDataCheck = -1 Then
Me.LocationDataEntered.Enabled = True
Else
Me.LocationDataEntered.Enabled = False
End If
End Sub

I tried using it in the BeforeUpdate. It's working, but you have to click the box twice. I tried putting it in every other instance: OnEnter, OnClick, it works with all of them, but only after the second click of the checkbox. Any idea on what might be going on?

Thanks!!
 
OMEGA - I just got it!! I just switched my False and True statements! Thanks again!
 
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??
 
Status
Not open for further replies.

Part and Inventory Search

Sponsor

Back
Top