Consulting

Results 1 to 4 of 4

Thread: Function to return Boolean

  1. #1
    VBAX Regular
    Joined
    Nov 2014
    Posts
    47
    Location

    Function to return Boolean

    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


  2. #2
    Distinguished Lord of VBAX VBAX Grand Master Bob Phillips's Avatar
    Joined
    Apr 2005
    Posts
    25,453
    Location
    Function CheckboxStatus(x As String) As Boolean
    CheckboxStatus = UserForm1.Controls(x).Value
    End Function
    
    If CheckboxStatus("Checkbox1") Then
    ____________________________________________
    Nihil simul inventum est et perfectum

    Abusus non tollit usum

    Last night I dreamed of a small consolation enjoyed only by the blind: Nobody knows the trouble I've not seen!
    James Thurber

  3. #3
    Distinguished Lord of VBAX VBAX Grand Master Bob Phillips's Avatar
    Joined
    Apr 2005
    Posts
    25,453
    Location
    A better way

    Function CheckboxStatus(x As Object) As Boolean
    CheckboxStatus = x.Value
    End Function
    
    
    If CheckboxStatus(UserForm1.CheckBox1) Then
    ____________________________________________
    Nihil simul inventum est et perfectum

    Abusus non tollit usum

    Last night I dreamed of a small consolation enjoyed only by the blind: Nobody knows the trouble I've not seen!
    James Thurber

  4. #4
    VBAX Regular
    Joined
    Nov 2014
    Posts
    47
    Location
    Great. Thank you.

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts
  •