vendredi 10 avril 2015

Word Form - using VBA to enable textbox on checkbox click

I have the following VBA code to enable a textbox everytime a checkbox is clicked.



Private Sub CheckName1_Click()
If CheckName1.Value = True Then
TextName1.Enabled = False
TextName1.SpecialEffect = fmSpecialEffectFlat
Else
TextName1.Enabled = True
TextName1.SpecialEffect = fmSpecialEffectSunken
End If
End Sub


The problem is my document will probably have 30 of these by the time I am done (CheckName1, CheckName2, CheckRent1, CheckRent2, etc). I am already having trouble with Word lagging, so I'd like to create a subroutine that will call this sub instead of copy/pasting it again and again.


I haven't spent a lot of time with functions and the like- and even less with VBA. I just know the basics and they always make my head spin. So, this is what I have.


I just don't know how to pass the textbox parameter, or if I even have the checkbox parameter right.


And if this is close, do I still create a call for each checkbox?



Private Sub CheckName1_Click()
Call NA
End Sub

Private Sub NA(checkbox, textbox)
If checkbox.value = True Then
textbox.Enabled = False
textbox.SpecialEffect = fmSpecialEffectFlat
Else
textbox.Enabled = True
textbox.SpecialEffect = fmSpecialEffectSunken
End Sub


Thanks in advance for any help!


Aucun commentaire:

Enregistrer un commentaire