PDA

View Full Version : [SOLVED:] Function to return Boolean



sindrefm
01-23-2015, 02:44 AM
Hi,

I want a function where I can add the name of the Checkbox(ex. CheckBox1, CheckBox2 etc.) and execute code if that Checkbox is False.
I have tried the following code, but it wont work. Anyone knows that is wrong here?
Thanks.

Function Checkbox(x As String) As Boolean
UserForm1.x.Value = False
End Function

If Checkbox(Checkbox1) Then
.......
End If

Bob Phillips
01-23-2015, 04:00 AM
Function CheckboxStatus(x As String) As Boolean
CheckboxStatus = UserForm1.Controls(x).Value
End Function

If CheckboxStatus("Checkbox1") Then

Bob Phillips
01-23-2015, 04:03 AM
A better way


Function CheckboxStatus(x As Object) As Boolean
CheckboxStatus = x.Value
End Function


If CheckboxStatus(UserForm1.CheckBox1) Then

sindrefm
01-23-2015, 06:50 AM
Great. Thank you.