Results 1 to 3 of 3

Thread: SQL in Excel

  1. #1
    Junior Member
    Join Date
    Sep 2011
    Posts
    8
    Rep Power
    0

    SQL in Excel

    Hi I am trying to run SQL in EXcel on data stored in Sheet2 of same workbook.
    I am tryting to fill a combo box using SQL queries ..The list populating is dependent
    on selection made in another drop down.eg

    A japan
    B india
    B UK
    A germany
    A italy
    B France

    so if A is selected I want the other combo box to be populated with japan,germany and Italy...
    please help wth the code for running the SQL

  2. #2
    Administrator Admin's Avatar
    Join Date
    Mar 2011
    Posts
    1,122
    Rep Power
    10
    Hi Nishant,

    It's recommend that not to query using ADO on an open excel workbook. More details can be found here;

    BUG: Memory leak occurs when you query an open Excel worksheet by using ActiveX Data Objects (ADO)


    You may also interested this link: http://www.excelfox.com/forum/f12/de...-formulas-111/
    Cheers !

    Excel Range to BBCode Table
    Use Social Networking Tools If You Like the Answers !

    Message to Cross Posters

    @ Home - Office 2010/2013/2016 on Win 10 (64 bit); @ Work - Office 2016 on Win 10 (64 bit)

  3. #3
    Senior Member
    Join Date
    Apr 2011
    Posts
    190
    Rep Power
    14
    I read the article about the memory leak - below is the code I use to read my Access table(s) - so I guess I am going to run into the memory problem. Can you suggest another method of connecting to Access or SQL for that matter.

    Is there a way I can monitor the amount of free memory - in the olden days the 'Free' command fullfilled that purpose - But I am not sure what replaces that command.

    Code:
    Public Sub FindFirstLastDates(strDBPath As String, DB_PW As String)
        Dim adoConn     As Object
        Dim rstRec      As Object
        Set adoConn = CreateObject("ADODB.Connection")
        Set rstRec = CreateObject("ADODB.Recordset")
        strTable = "SampleHeader"
        On Error Resume Next
        With adoConn
            Err.Clear
            .provider = "Microsoft.Jet.Oledb.4.0"
            .Properties("Jet OLEDB:Database Password") = DB_PW
            .Open "Data Source=" & strDBPath
            If Err.Number <> 0 Then
                On Error GoTo 0
                Exit Sub
            End If
        End With
        rstRec.Open "Select * from " & strTable & " ORDER BY SampleDateTime", adoConn, 3, 3
        rstRec.movefirst
        TxtStartDate.Text = Format(rstRec.fields("SampleDateTime"), "YYYY/MM/DD")
        rstRec.movelast
        TxtEndDate.Text = Format(rstRec.fields("SampleDateTime"), "YYYY/MM/DD")
        adoConn.Close
        On Error GoTo 0
    End Sub
    Last edited by Rasm; 01-24-2012 at 06:29 AM.
    xl2007 - Windows 7
    xl hates the 255 number

Similar Threads

  1. SQL output from Excel VBA macro
    By goldenbutter in forum Excel Help
    Replies: 3
    Last Post: 05-07-2013, 08:07 PM
  2. Upload Excel Data to SQL Table
    By littleiitin in forum Excel and VBA Tips and Tricks
    Replies: 3
    Last Post: 08-22-2012, 11:02 AM
  3. Replies: 2
    Last Post: 11-17-2011, 07:49 PM
  4. Execute SQL From Excel (VBA)
    By Mechanic in forum Excel and VBA Tips and Tricks
    Replies: 8
    Last Post: 10-02-2011, 04:30 PM
  5. Execute SQL From Excel (VBA)
    By Mechanic in forum Excel Help
    Replies: 0
    Last Post: 05-13-2011, 10:27 AM

Posting Permissions

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