I have an Excel VBA code which has the following function. Of course there are other subs/ functions based on the recordSet which are used to populate the different spreadsheets in the workbook.Issue: When the recordSet is Empty then a run-time error '13' Type: mismatch comes up. How can I add to this code to check if empty then stop populating the sheet.
Function GetSqlResultsAsArray(qry As String) As Variant Dim conn As New ADODB.Connection Dim recordSet As ADODB.recordSet'connection string here conn.Open ConnectionString:="" Set recordSet = conn.Execute(qry) If Not recordSet.EOF And Not recordSet.BOF Then GetSqlResultsAsArray = recordSet.GetRows End If conn.CloseEnd Function
The next relevant code is: I want to stop resultsArray getting populated if the above code returns empty or null to void the Run-time error '13'. I do not know how to amend the below to do this.
resultSql = GetResultSqlStatement(customer, product, startDate, endDate, productType) productSql = GetProductSqlStatement(product, customer, startDate, endDate)'Call getJMF(productSql) Dim resultsArray() As Variant resultsArray = GetSqlResultsAsArray(resultSql)