Consulting

Results 1 to 5 of 5

Thread: Convert sql to vba code

  1. #1

    Convert sql to vba code

    Hi,

    I have a spreadsheet that have many tabs aka w1,w2,w3.... and so on. I have a table that queried one of those tab example bottom

    SELECT `W48$`.Cost, `W48$`.`Customer Name`, `W48$`.`Customer#`, `W48$`.GP, `W48$`.Margin, `W48$`.Qty, `W48$`.Sales, `W48$`.Wgt, `W48$`.WK
    FROM `C:\sales\WK06`.`W48$` `W48$`

    Every week I would go into the sql and edit w48 to w49 and so on.

    I would like to put this a macro that I could just change the # so I dont have to manually change it every time.

    any help would be greatly appreciated

  2. #2
    Distinguished Lord of VBAX VBAX Grand Master Bob Phillips's Avatar
    Joined
    Apr 2005
    Posts
    25,453
    Location
    Obviously untested

    [vba]

    SQLString = "SELECT '" & Range("A1").Value & "$'.Cost, " & _
    " '" & Range("A1").Value & "$'.'Customer Name', " & _
    " '" & Range("A1").Value & "$'.'Customer#', " & _
    " '" & Range("A1").Value & "$'.GP, " & _
    " '" & Range("A1").Value & "$'.Margin, " & _
    " '" & Range("A1").Value & "$'.Qty, " & _
    " '" & Range("A1").Value & "$'.Sales, " & _
    " '" & Range("A1").Value & "$'.Wgt, " & _
    " '" & Range("A1").Value & "$'.WK" & _
    "FROM 'C:\sales\WK06'.'" & Range("A1").Value & "$' '" & Range("A1").Value & "$'"
    [/vba]
    ____________________________________________
    Nihil simul inventum est et perfectum

    Abusus non tollit usum

    Last night I dreamed of a small consolation enjoyed only by the blind: Nobody knows the trouble I've not seen!
    James Thurber

  3. #3
    Thank you I will give it a shot and post back with the result.

  4. #4
    It works, just have change a couple things but it works.

    Thanks again

  5. #5
    Distinguished Lord of VBAX VBAX Grand Master Bob Phillips's Avatar
    Joined
    Apr 2005
    Posts
    25,453
    Location
    That'sgood, I was guessing a bit as to where your code was at and what you wanted, but the boy done good.
    ____________________________________________
    Nihil simul inventum est et perfectum

    Abusus non tollit usum

    Last night I dreamed of a small consolation enjoyed only by the blind: Nobody knows the trouble I've not seen!
    James Thurber

Posting Permissions

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