Results 1 to 40 of 45

Thread: Unasked Question is the Dumb Question

Threaded View

  1. #9
    Addicted Member
    Join Date
    Feb 2008
    Location
    Hamburg
    Posts
    138

    Re: Unasked Question is the Dumb Question

    If you want to do it SQL style, you can stick to the Excel spreadsheet and use it like a DB...if you dont do this often and performance or data security are not of the issue...

    You need to connect to your "Excel DB" and then you can run all SQL queries you like.

    The query below should be pretty close to what you want to do.

    Where would your data be and what table to query? On your spreadsheet select the relevant data and give that range a name. Tada: your table name.

    http://www.connectionstrings.com/?carrier=excel2007
    http://www.connectionstrings.com/?carrier=excel

    To connect:
    Code:
    Dim cnn As ADODB.Connection
    Dim cmd As ADODB.Command
    Dim rst as ADODB.recordset
    Dim strQry As String
    
    
    Set cnn = New ADODB.Connection
    cnn.ConnectionString = "Provider=Microsoft.Jet.OLEDB.4.0;Data Source=C:\MyExcel.xls;Extended Properties=""Excel 8.0;HDR=Yes;IMEX=1"";"
    cnn.Open
    
    strQry = "SELECT * FROM myDataRange WHERE myField Like '*ABC*'
    
    Set cmd = New ADODB.Command
    Set cmd.ActiveConnection = cnn
    cmd.CommandType = adCmdText
    cmd.CommandText = strQry
    Set rst = New ADODB.Recordset
    Set rst = cmd.Execute
    
    'manipulate write or do whatever to your data here
    
    rst.close
    set rst = nothing
    set cmd = nothing
    set cnn = nothing
    Last edited by BManke; Feb 7th, 2008 at 04:02 AM. Reason: forgetfulness

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