CodexBloom - Programming Q&A Platform

VBA scenarios 438: Object Doesn't Support This Property or Method When Calling a Custom Function

👀 Views: 26 💬 Answers: 1 📅 Created: 2025-06-14
vba userform error-handling

I'm prototyping a solution and I'm trying to implement I'm stuck on something that should probably be simple. Hey everyone, I'm running into an issue that's driving me crazy. I'm working with a frustrating behavior in my VBA code when I try to call a custom function from a button on my UserForm. The behavior message says 'Run-time behavior 438: Object doesn't support this property or method.' This occurs specifically when I try to access a property of an object that is being passed as an argument to the function. Here's a simplified version of my code: ```vba Private Sub btnCalculate_Click() Dim result As Double result = CalculateSum(Me.txtValue1, Me.txtValue2) MsgBox "The total is: " & result End Sub Function CalculateSum(val1 As Variant, val2 As Variant) As Double If IsNumeric(val1) And IsNumeric(val2) Then CalculateSum = val1 + val2 Else CalculateSum = 0 End If End Function ``` I've ensured that both `txtValue1` and `txtValue2` are text boxes on my UserForm where users input numeric values. However, I suspect that the scenario arises because I'm passing the text box controls directly to the function instead of their values. I tried changing the function call to `CalculateSum(Me.txtValue1.Value, Me.txtValue2.Value)` but it still throws the same behavior. I’ve also checked that the controls are properly named and I can confirm that they have valid numeric inputs at the time of the button click. I would appreciate any insights on why this behavior occurs and how to resolve it. Am I missing something in the way I'm referencing the controls or calling the function? This is part of a larger API I'm building. I'd really appreciate any guidance on this. For context: I'm using Vba on CentOS. Has anyone dealt with something similar? The project is a service built with Vba.