"sub or function not defined" compile error in Excel macro

Posted on 2003-02-25
Medium Priority
Last Modified: 2012-05-04
I am recieving the compile error of "sub or function not defined" when attempting to do an execution on a macro in Excel, however I do not understand why.

The debugger is listing this line of code as the problem:
"Function GetPossibleAnswers(ByVal iResponseGroupID As Integer, ByRef arAnswers() As Variant)"

Am I not able to pass by reference a variant array in this manner?

Here is the complete code:

Function NoNulls(vValue, bIsNumber)
'Purpose: Automatically convert null values to zero or empty string
' bIsNumber denotes if a 0 or an empty string should be used if null encountered
' otherwise returns non-null value
 If IsNull(vValue) Then
   If bIsNumber Then NoNulls = 0 Else NoNulls = ""
   NoNulls = vValue
 End If
End Function

Function GetPossibleAnswers(ByVal iResponseGroupID As Integer, ByRef arAnswers() As Variant)
  Const SQLCONNECTION As String = "Driver={SQL Server};Server=localhost;Database=QA;UID=SA;PWD="
  Dim strSP
  Dim rsAnswers As New ADODB.Recordset
  Dim objSQLDB As New ADODB.Connection
  Dim iCounter
  strSP = "spGetResponseGroupData " & iResponseGroupID
  rsAnswers.Open strSP, objSQLDB
  If Not rsAnswers.EOF Then
    iCounter = 0
    While Not rsAnswers.EOF
      arAnswers(i, 0) = NoNulls(rsQuestion("AnswerID"), 1)
      arAnswers(i, 1) = NoNulls(rsQuestion("Answer"), 0)
      arAnswers(i, 2) = NoNulls(rsQuestion("Explanation"), 0)
      arAnswers(i, 3) = NoNulls(rsQuestion("Scorable"), 1)
      iCounter = iCounter + 1
  End If
  Set rsAnswers = Nothing
  Set objSQLDB = Nothing
End Function

Sub test()
  Dim arAnswers(10, 4) As Variant
  Call GetPossibleAnswers(3, arAnswers())
  For intI = 0 To UBound(arAnswers())
    MsgBox arAnswers(intI, 1)
  Next intI
End Sub
Question by:Divaqs
Welcome to Experts Exchange

Add your voice to the tech community where 5M+ people just like you are talking about what matters.

  • Help others & share knowledge
  • Earn cash & points
  • Learn & ask questions

Author Comment

ID: 8020964
By the way, I did try
"Function GetPossibleAnswers(ByVal iResponseGroupID As Integer, ParamArray arAnswers() As Variant)"

And still receive the same error.

Accepted Solution

gakibbie earned 400 total points
ID: 8021521
A few things:
1) You have rsQuestion in the GetPossibleAnswers Function
2) You have i in the GetPossibleAnswers Function
3) You have the a different variable name in your second GetPossibleAnswers function params in your second comment.

It looks like a case of mixed up variable names to me...
I hope this helps.

Featured Post

Office 365 Training for Admins - 7 Day Trial

Learn how to provision tenants, synchronize on-premise Active Directory, implement Single Sign-On, customize Office deployment, and protect your organization with eDiscovery and DLP policies.  Only from Platform Scholar.

Question has a verified solution.

If you are experiencing a similar issue, please ask a related question

You need to know the location of the Office templates folder, so that when you create new templates, they are saved to that location, and thus are available for selection when creating new documents.  The steps to find the Templates folder path are …
This article describes a serious pitfall that can happen when deleting shapes using VBA.
The view will learn how to download and install SIMTOOLS and FORMLIST into Excel, how to use SIMTOOLS to generate a Monte Carlo simulation of 30 sales calls, and how to calculate the conditional probability based on the results of the Monte Carlo …
Learn how to create and modify your own paragraph styles in Microsoft Word. This can be helpful when wanting to make consistently referenced styles throughout a document or template.

764 members asked questions and received personalized solutions in the past 7 days.

Join the community of 500,000 technology professionals and ask your questions.

Join & Ask a Question