I have a form called Form1. In Form1, I have the following code –
Dim details As clsDetails
Set details = getDetials(1) ' This fails. It doesn't assign a value.
The getDetails function is declared in a separate module as follows-
Public Function getDetials(detailNumber As Integer) As clsDetails
Dim details As clsDetails
Select Case detailNumber
Case "1"
Debug.Print "Inside case1"
Set details = getDetail1()
Debug.Print details.comment ' This prints correctly.
End Select
Set getDetails = details
End Function
However, when I execute the above code, somehow, the details variable in Form1 doesn’t get set, even though the getDetails function is called and prints the details correctly inside it. How to rectify this?
Do you have the
Option Explicitkeyword defined?It looks like you might have a typo. Your function is called
getDetials, but the variable you’re setting the result to isgetDetails, so the return value is not getting set.I fixed the typo and everything works as expected on my end. Using the
Option Explicitkeyword will catch these types of errors.