1

Hi when I run the code I get the "Not sub or function declared" when it's, I have 3 functions and the error just happens with this one

Public Function atleastOne(ParamArray params() As Variant) As Boolean
    Dim checked As Boolean
    For Each param In params
        If param.Caption = Char(254) Then
            checked = True
    Next
    
    If checked Then
        MsqBox "Tiene que seleccionar una opción", "Error"
        atleastOne = False
    Else
        atleastOne = True
    End If
End Function

and I call the function here

Private Sub toPreg2_Click()
    Dim isSelected As Boolean
    isSelected = atleastOne(op1A, op1B, op1C, op1D, op1E)
End Sub
0

1 Answer 1

5

There are three issues I see right off bat

  • Char is not a function within VBA. What you are probably trying is Chr
  • MsqBox should be Msgbox
  • and you are missing and End If statement in your first conditional.
Public Function atleastOne(ParamArray params() As Variant) As Boolean
    Dim checked As Boolean
    For Each param In params
        If param.Caption = Chr(254) Then ' `Chr` vs `Char`
            checked = True
        End If  ' Was missing
    Next
    
    If checked Then
        MsgBox "Tiene que seleccionar una opción", "Error" ' `Msgbox` vs `MsqBox`
        atleastOne = False
    Else
        atleastOne = True
    End If
End Function

Private Sub toPreg2_Click()
    Dim isSelected As Boolean
    isSelected = atleastOne(op1A, op1B, op1C, op1D, op1E)
End Sub
Sign up to request clarification or add additional context in comments.

1 Comment

Hi Robert, thanks for answering, yes, it was the 'Char vs Chr' sorry for my dumb question, again, thank you!

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.