Sign Up

Sign Up to our social questions and Answers Engine to ask questions, answer people’s questions, and connect with other people.

Have an account? Sign In

Have an account? Sign In Now

Sign In

Login to our social questions & Answers Engine to ask questions answer people’s questions & connect with other people.

Sign Up Here

Forgot Password?

Don't have account, Sign Up Here

Forgot Password

Lost your password? Please enter your email address. You will receive a link and will create a new password via email.

Have an account? Sign In Now

You must login to ask a question.

Forgot Password?

Need An Account, Sign Up Here

Please briefly explain why you feel this question should be reported.

Please briefly explain why you feel this answer should be reported.

Please briefly explain why you feel this user should be reported.

Sign InSign Up

The Archive Base

The Archive Base Logo The Archive Base Logo

The Archive Base Navigation

  • SEARCH
  • Home
  • About Us
  • Blog
  • Contact Us
Search
Ask A Question

Mobile menu

Close
Ask a Question
  • Home
  • Add group
  • Groups page
  • Feed
  • User Profile
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Buy Points
  • Users
  • Help
  • Buy Theme
  • SEARCH
Home/ Questions/Q 7836571
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: June 2, 20262026-06-02T14:12:47+00:00 2026-06-02T14:12:47+00:00

In an Excel macro, I have a function defined like to return a Recordset

  • 0

In an Excel macro, I have a function defined like to return a Recordset like so

Function GetCommissionDataRecordset(doctorCode As String) As ADODB.Recordset
    Set GetCommissionDataRecordset = New ADODB.Recordset
    .
    . ' setup the connection and SQL string...
    .
    GetCommissionDataRecordset.Open strSQL
end function

and I attempt to call the function like so

sub tester()
    'Dim oRecSet As ADODB.Recordset  ' this doesn't work, needs to be a variant
    Dim oRecSet As Variant
    Set oRecSet = GetCommissionDataRecordset("GC")
    'Copy Data to Excel'

    ActiveSheet.Range("a1").CopyFromRecordset (oRecSet)
end sub

If in the tester subprocedure I define oRecSet as ADODB.Recordset, I get a runtime error when doing the CopyFromRecordset.

The error goes away when I define oRecSet as a Variant.

The runtime error is 430 Class does not support Automation or does not support expected interface.

When the error occurs, Watch tells me that the type of oRecSet is Recordset/Recordset

When I use the variant approach, Watch tells me that the type of oRecSet is Variant/Object/Recordset

Inspecting the properties of the object in Watch seems to show no difference to me.

What’s going on?

  • 1 1 Answer
  • 0 Views
  • 0 Followers
  • 0
Share
  • Facebook
  • Report

Leave an answer
Cancel reply

You must login to add an answer.

Forgot Password?

Need An Account, Sign Up Here

1 Answer

  • Voted
  • Oldest
  • Recent
  • Random
  1. Editorial Team
    Editorial Team
    2026-06-02T14:12:50+00:00Added an answer on June 2, 2026 at 2:12 pm

    The CopyFromRecordSet expects a Variant parameter. As you are (accidentally?) sending the recordset by value, because of the () around oRecSet, the type matching seems to be quite strict, causing an error.

    If you change your call to:

    ActiveSheet.Range("a1").CopyFromRecordset oRecSet
    

    it will work when oRecSet is a RecordSet, but then you will not be forcing a By Value parameter passing. Actually the function declaration doesn’t specify if the parameter is ByVal or ByRef, but one wouldn’t expect a “copy from recordset” method to change it’s contents.

    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

I have an Excel worksheet that has the following macro. I'd like to loop
I have the below stored in excel macro:- Sub Sales() Dim StrSQl As String
I have made a minor change to an Excel macro, and although it worked
I have created a macro for excel which will pop up form that contains
I have a static empty chart in Excel, I have a macro which pulls
I have written a VBA macro in an excel spreadsheet that opens all workbooks
I have exported email mesages to excel by using a macro. By using Mid
i have a server where resides an excel macro there will be about 10
I am trying to display milliseconds in an Excel macro. I have a column
I have an Excel file with macro. In this file, there is a user

Explore

  • Home
  • Add group
  • Groups page
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Users
  • Help
  • SEARCH

Footer

© 2021 The Archive Base. All Rights Reserved
With Love by The Archive Base

Insert/edit link

Enter the destination URL

Or link to existing content

    No search term specified. Showing recent items. Search or use up and down arrow keys to select an item.