Results 1 to 8 of 8

Thread: Range().copyfromRecordset not working for one recordset

  1. #1

    Thread Starter
    Junior Member
    Join Date
    Aug 2005
    Posts
    29

    Range().copyfromRecordset not working for one recordset

    Let me describe my problem. Within Excel I hit an oracle database and retreive some data and then I do a range("A1").copyFromRecordset dbRS, where dbRS is the recordset. I've done this a million times and it works fine. Then I decided to do the same thing for one query that was a little more complex, but it throws a very generic " " error

    So I figure, something is wrong with the recordset, but not so. When I do this:

    VB Code:
    1. Do While Not dbRS.EOF
    2.     Debug.Print (dbRS.Fields(1) & " " & dbRS.Fields(4) & " " & dbRS.Fields(5))
    3.     dbRS.MoveNext
    4. Loop

    It prints out all the fields fine. I also decide that maybe it's the SQL statement, so I output the SQL statement to Golden (an Oracle client) and the query runs fine as well.

    The error I get is the following:
    VB Code:
    1. There was an error Method 'CopyFromRecordset' of object 'Range' failed

    So basically I was wondering if anybody can think of any reason why this recordset isn't working with the CopyFromRecorset function or if there is more I can do to troubleshoot. I can't show most of my code because there is a lot of private stuff in there, and I'm not sure how helpful it would be either. Please help if you can. Thank you.

  2. #2
    Ex-Super Mod RobDog888's Avatar
    Join Date
    Apr 2001
    Location
    LA, Calif. Raiders #1 AKA:Gangsta Yoda™
    Posts
    60,709

    Re: Range().copyfromRecordset not working for one recordset

    If the Recordset object contains fields with OLE objects in them then it will give that error.
    Also, only works with ADO or DAO rs'
    VB/Office Guru™ (AKA: Gangsta Yoda®)
    I dont answer coding questions via PM. Please post a thread in the appropriate forum.

    Microsoft MVP 2006-2011
    Office Development FAQ (C#, VB.NET, VB 6, VBA)
    Senior Jedi Software Engineer MCP (VB 6 & .NET), BSEE, CET
    If a post has helped you then Please Rate it!
    Reps & Rating PostsVS.NET on Vista Multiple .NET Framework Versions Office Primary Interop AssembliesVB/Office Guru™ Word SpellChecker™.NETVB/Office Guru™ Word SpellChecker™ VB6VB.NET Attributes Ex.Outlook Global Address ListAPI Viewer utility.NET API Viewer Utility
    System: Intel i7 6850K, Geforce GTX1060, Samsung M.2 1 TB & SATA 500 GB, 32 GBs DDR4 3300 Quad Channel RAM, 2 Viewsonic 24" LCDs, Windows 10, Office 2016, VS 2019, VB6 SP6

  3. #3
    Super Moderator si_the_geek's Avatar
    Join Date
    Jul 2002
    Location
    Bristol, UK
    Posts
    41,974

    Re: Range().copyfromRecordset not working for one recordset

    I could be wrong, but I think you also get that error if you have more than 255 columns or 65536 records.

  4. #4

    Thread Starter
    Junior Member
    Join Date
    Aug 2005
    Posts
    29

    Re: Range().copyfromRecordset not working for one recordset

    I am positive the latter dimensional problems is not the issue because I ran the sql query in another client and it is well within range. As for the OLE objects...how does one get OLE objects into a recordset? I am really just running a SQL query on an oracle database pulling up text.

    Also let me also mention that everything was working fine, even this macro that I am describing right now before my excel was changed from Office XP to Office 2003. In addition to the strangeness all my other scripts run fine, it is really just this one. I am so lost.

    Since my first post I've tried outputting the recordset to a text file by going through each field like

    while not dbRS.eof do
    For i = 1 to 31
    [output to file]-> dbRS.fields(i)
    next i
    loop

    or something like that and that seems to work too.

  5. #5
    Super Moderator si_the_geek's Avatar
    Join Date
    Jul 2002
    Location
    Bristol, UK
    Posts
    41,974

    Re: Range().copyfromRecordset not working for one recordset

    I'm not sure what data types Oracle has, but are any of the data types for those fields something like "Memo" (or other "very long" text) or a custom data type?
    These will typically be seen as OLE objects within a recordset.

    If there isn't anything obvious, try removing the fields one at a time to see if you can find which one is causing the problem.

    Are you using ADO or DAO to get your recordset? Whichever you are using, it may be worth trying the other.

  6. #6

    Thread Starter
    Junior Member
    Join Date
    Aug 2005
    Posts
    29

    Re: Range().copyfromRecordset not working for one recordset

    hmm, interesting that you mention that there is one particularly large field that is like a memo/notes. I'll try removing it and see what happens. The thing is though, lets say that field is field 5. If I do

    VB Code:
    1. do while not dbRS.EOF
    2.     msgbox dbRS.fields(5)
    3.     dbRS.movenext
    4. loop

    it comes out fine and it prints the field out fine. I hate to say this, because i hate it when others say it since it really doesn't help much, but the damn macro was working fine just a few days ago, and coincidentally I was out on jury duty those few days and my office got upgraded to 2003, and now it doesn't work. It's a strange thing. I am using ADO by the way, I'm afraid of moving to DAO, I always thought ADO was the way to go.

  7. #7
    Super Moderator si_the_geek's Avatar
    Join Date
    Jul 2002
    Location
    Bristol, UK
    Posts
    41,974

    Re: Range().copyfromRecordset not working for one recordset

    You can use OLE fields without a problem in VB/VBA, it is CopyFromRecordset that can't work with them. There may be some conversion that can be done on the problem field(s) to make them non-OLE.

    I don't know why it would have "broken" by upgrading to Office 2003, I never had any issues with it (including CopyFromRecordset in several programs).

    ADO is certainly preferable, but DAO may work... just offering an alternative in case we can't find another solution

  8. #8
    Ex-Super Mod RobDog888's Avatar
    Join Date
    Apr 2001
    Location
    LA, Calif. Raiders #1 AKA:Gangsta Yoda™
    Posts
    60,709

    Re: Range().copyfromRecordset not working for one recordset

    Taking out the memo field is a good test. There may also be a unsupported or invalid character in the field that is causing the issue too?
    VB/Office Guru™ (AKA: Gangsta Yoda®)
    I dont answer coding questions via PM. Please post a thread in the appropriate forum.

    Microsoft MVP 2006-2011
    Office Development FAQ (C#, VB.NET, VB 6, VBA)
    Senior Jedi Software Engineer MCP (VB 6 & .NET), BSEE, CET
    If a post has helped you then Please Rate it!
    Reps & Rating PostsVS.NET on Vista Multiple .NET Framework Versions Office Primary Interop AssembliesVB/Office Guru™ Word SpellChecker™.NETVB/Office Guru™ Word SpellChecker™ VB6VB.NET Attributes Ex.Outlook Global Address ListAPI Viewer utility.NET API Viewer Utility
    System: Intel i7 6850K, Geforce GTX1060, Samsung M.2 1 TB & SATA 500 GB, 32 GBs DDR4 3300 Quad Channel RAM, 2 Viewsonic 24" LCDs, Windows 10, Office 2016, VS 2019, VB6 SP6

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts
  •  



Click Here to Expand Forum to Full Width