B
Bobbak
Hello All,
I was wondering if it is possible to do this; I have a form that has
number of text boxes that when a button is clicked it turns into combo
boxes, simply by toggling the visibility to the box. For example 3
textboxes, txtA, txtB, and txtC, and 3 combo boxes, cmbA, cmbB, and
cmbC. Now when the form is open all three of the text boxes are
visible, and the combo boxes are invisible, until a button is pressed,
and the text boxes become invisible, and the combo boxes become
visible.
As it stand the cold for the button goes like this:
Private Sub Toggle_Click()
If Forms!Form1.txtA.visible = True Then
Forms!Form1.txtA.visible = False
Forms!Form1.cmbA.visible = True
Else
Forms!Form1.txtA.visible = True
Forms!Form1.cmbA.visible = False
End If
If Forms!Form1.txtB.visible = True Then
Forms!Form1.txtB.visible = False
Forms!Form1.cmbB.visible = True
Else
Forms!Form1.txtB.visible = True
Forms!Form1.cmbB.visible = False
End If
If Forms!Form1.txtC.visible = True Then
Forms!Form1.txtC.visible = False
Forms!Form1.cmbC.visible = True
Else
Forms!Form1.txtC.visible = True
Forms!Form1.cmbC.visible = False
End If
End Sub
Now my question is, if there is a way to simplify this code using a
Function Module, and passing the variable names as the parameters.
I was wondering if it is possible to do this; I have a form that has
number of text boxes that when a button is clicked it turns into combo
boxes, simply by toggling the visibility to the box. For example 3
textboxes, txtA, txtB, and txtC, and 3 combo boxes, cmbA, cmbB, and
cmbC. Now when the form is open all three of the text boxes are
visible, and the combo boxes are invisible, until a button is pressed,
and the text boxes become invisible, and the combo boxes become
visible.
As it stand the cold for the button goes like this:
Private Sub Toggle_Click()
If Forms!Form1.txtA.visible = True Then
Forms!Form1.txtA.visible = False
Forms!Form1.cmbA.visible = True
Else
Forms!Form1.txtA.visible = True
Forms!Form1.cmbA.visible = False
End If
If Forms!Form1.txtB.visible = True Then
Forms!Form1.txtB.visible = False
Forms!Form1.cmbB.visible = True
Else
Forms!Form1.txtB.visible = True
Forms!Form1.cmbB.visible = False
End If
If Forms!Form1.txtC.visible = True Then
Forms!Form1.txtC.visible = False
Forms!Form1.cmbC.visible = True
Else
Forms!Form1.txtC.visible = True
Forms!Form1.cmbC.visible = False
End If
End Sub
Now my question is, if there is a way to simplify this code using a
Function Module, and passing the variable names as the parameters.