Enable/Disable textbox when checkbox is checked for only one record at a time

clloftus

Registered User.
Local time
Today, 09:32
Joined
Mar 15, 2012
Messages
24
I have searched through the various forums, and have figured out how to disable a textbox when a checkbox is checked. The problem I am having is, this carries on to every record. When I go to the next record (record 2, 3, and so forth), the textbox is disabled, even though the VM checkbox is not checked.

Here is the code that I have:

Private Sub VM AfterUpdate()
If Me.VM = -1 Then
Me.NSAID.Enabled = True
Else
Me.NSAID.Enabled = False
End If

End Sub


Private Sub frmAsset ()
If Me.VM = -1 Then
Me.NSAID.Enabled = True
Else
Me.NSAID.Enabled = False
End If

End Sub

Next, is there an easy way to write this code if I have more than one textbox to disable when the checkbox is checked?

Thank you in advance for your assistance.
 
You would need the code in the Current event to handle the changing of records.

You can use Boolean logic and have one line:

Me.NSAID.Enabled = Me.VM

For multiple textboxes, you can simply do

Me.NSAID.Enabled = Me.VM
Me.OtherTextbox.Enabled = Me.VM

If you have a lot, you can loop the controls of the form and use the Tag property to set the appropriate textboxes.
 
Thank you for your response. I made the change, however, the boxes are still greyed out once the checkbox is checked for every record. The checkbox is not checked for every record, just the boxes are greyed out. Below is the change that I made.

I'm fairly new to this, so I apologize in advance if I misunderstood what you said to do.

Private Sub VM AfterUpdate()
If Me.VM = -1 Then
Me.NSAID.Enabled = True
Else
Me.NSAID.Enabled = False
End If

End Sub


Private Sub frmAsset ()
Me.NSAID.Enabled = Me.VM
End Sub
 
I also tried and still get the same results: Record 1, checkbox checked, textboxes greyed, Record 2, checkbox unchecked, textboxes greyed. Again, thank you for your assistance.

Private Sub VM AfterUpdate()
If Me.VM = -1 Then
Me.NSAID.Enabled = True
Else
Me.NSAID.Enabled = False
End If

End Sub


Private Sub frmAsset_Current ()
Me.NSAID.Enabled = Me.VM
End Sub
 
I got it figured out ... thank you for your efforts and assistance. I'm sure I'll be posting to this forum again in the future. It's a wonderful tool.
 

Users who are viewing this thread

Back
Top Bottom