Results 1 to 5 of 5

Thread: [RESOLVED] Populate a spreadsheet

  1. #1

    Thread Starter
    Lively Member
    Join Date
    Sep 2005
    Location
    Glasgow, Scotland
    Posts
    77

    Resolved [RESOLVED] Populate a spreadsheet

    I'm trying to write a VS2002 VB procedure that will read in the contents of a recordset and then output it to Excel, without having to actually go through the hassle of coding each individual cell movement. I've done something similar in CSV format, using the Write and Writeline commands to place the information. However, what I can't replicate in Excel is the movement from one cell to another - if I try to insert a tab between each cell, it simply concatenates the data into one cell, with tabs in between them.

    I'm going home now, but if someone knows what the solution is, I'm all ears
    Wise man once said: "Don't ever get married, just find a woman you don't like and buy her a house".
    According to ancient Chinese proverb, "Man with hole in pocket feels cocky all day".

  2. #2
    PowerPoster Static's Avatar
    Join Date
    Oct 2000
    Location
    Rochester, NY
    Posts
    9,390

    Re: Populate a spreadsheet

    look into

    CopyFromRecordset it will be your saviour
    JPnyc rocks!! (Just ask him!)
    If u have your answer please go to the thread tools and click "Mark Thread Resolved"

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

    Re: Populate a spreadsheet

    Watch this Static

    Since classic ADO is a secondary technology in .NET you should be using either ADO.NET or automating Access and Excel to get your results.

    Here is some code I wrote to output a new Excel workbook from an Access table/query.

    http://vbforums.com/showpost.php?p=2514577&postcount=8
    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

  4. #4

    Thread Starter
    Lively Member
    Join Date
    Sep 2005
    Location
    Glasgow, Scotland
    Posts
    77

    Angry Re: Populate a spreadsheet

    Quote Originally Posted by Static
    look into

    CopyFromRecordset it will be your saviour
    Hi Static

    I've got a few questions for you:

    1. Will CopyFromRecordset work when using VB.NET 2002 to empty the contents of a recordset into an Excel spreadsheet;
    2. Will I be able to control the names of the columns that appear in the output? I can't just have it dumping out the table column names as column headers, since the output is going to a Client;

    If it comes to it, I've got the ability to use Automation to populate the spreadsheet, but that's a bit of faffage that I could really live without at the moment.

    Thanks
    Wise man once said: "Don't ever get married, just find a woman you don't like and buy her a house".
    According to ancient Chinese proverb, "Man with hole in pocket feels cocky all day".

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

    Re: Populate a spreadsheet

    Not much control over the columns copied using the CopyFromRecordset method. You would have to adjust your query that populates your recordset.

    No field names will be populated. You have to code it by looping theough the fields collection of your recordset.

    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