Results 1 to 7 of 7

Thread: Mschart and Excel

  1. #1

    Thread Starter
    PowerPoster lintz's Avatar
    Join Date
    Mar 2003
    Location
    The 19th Hole
    Posts
    2,697

    Mschart and Excel

    Is it possible to use ADO in Excel to return a recordset?

    I've got about 1000 rows for my data that will be plotted on a MSChart but I don't want to loop from row 1 to row 1000 to get all the values.

    Can I use something like....
    VB Code:
    1. SELECT * FROM WorkSheetName Range A1 to A1000
    Last edited by lintz; Oct 10th, 2005 at 01:06 AM.

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

    Re: Mschart and Excel

    Yes, but you need to add the reference to ADO in the VBA IDE. Then its about the same as it is from outside of Excel. Then when you have your recordset you can show it on your chart/form.

    Why not use a chart inside Excel? Easier.

    Moved from Classic VB forum.
    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

    Thread Starter
    PowerPoster lintz's Avatar
    Join Date
    Mar 2003
    Location
    The 19th Hole
    Posts
    2,697

    Re: Mschart and Excel

    Thanks RobDog, so would my example query work or would it need to be re-written?

    VB Code:
    1. SELECT * FROM WorkSheetName Range A1 to A1000

    Also, if the spreadsheet was already open would it be a problem when connecting to it? If so, is there a way around it since it will be open when I want to run the query?
    Last edited by lintz; Oct 9th, 2005 at 07:35 PM.

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

    Re: Mschart and Excel

    Its no problem.

    You would want to use a querystring like this...

    VB Code:
    1. SELECT * FROM [Sheet1$A1:A1000]
    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

  5. #5

    Thread Starter
    PowerPoster lintz's Avatar
    Join Date
    Mar 2003
    Location
    The 19th Hole
    Posts
    2,697

    Re: Mschart and Excel

    I found the connection string from www.connectionstrings.com and this is what I've got. However it attempts to open up the spreadsheet again even though it's already open.

    VB Code:
    1. xlPath = App.Path & "\Research.xls"
    2.  
    3. strCn = "Provider=Microsoft.Jet.OLEDB.4.0;Data Source=" & xlPath & ";Extended Properties=""Excel 8.0;HDR=Yes;IMEX=1"""
    4.  
    5. sSQL = "SELECT DrawDown FROM [Trades Database$EG34:EG" & LastRow & "]"
    6. rsSelectedTrades.Open sSQL, strCn 'This line attempts to open the spreadsheet again.

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

    Re: Mschart and Excel

    What do you mean "attempts"? Visibly opens another instance or errors?
    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

  7. #7

    Thread Starter
    PowerPoster lintz's Avatar
    Join Date
    Mar 2003
    Location
    The 19th Hole
    Posts
    2,697

    Re: Mschart and Excel

    Yes, visibly opens another instance so I then have two copies of my spreadsheet open....

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