Microsoft® Excel® based database addin

 

+ Reply to Thread
Results 1 to 6 of 6
  1. #1
    Andrea is offline Junior Member
    Join Date
    Jul 2009
    Posts
    6

    Default Embed SQL Drill Results in Excel

    Hi!
    I am a complete newbie to the SQL/database world, so please forgive my ignorance. A co-worker suggested SQL drill for me to get the data I need from the oracle dtabase and then import it into excel. This program is awesome! Thanks!
    I would like to embed the results of the query so that it is updated by hitting the refresh button, or something like that. Given that the query results change ofter, in order to make it functional for what I am trying to achieve, I cannot open SQL Drill, run the querry again and keep pasting the results in excel everytime.
    I havce searched for a way to do this, but have not been able to find it.
    Please let me know if this is possible & if so, how can I achieve it.
    Thanks in advance for your time & help!
    -Andrea

  2. #2
    admin's Avatar
    admin is offline Administrator
    Join Date
    Apr 2008
    Location
    Dublin, NYC
    Posts
    333
    Blog Entries
    1

    Default

    Hi Andrea

    Sorry for delay there.
    You should be able to see that up easily enough. Here is one way you could check out.

    First thing would be to setup the query and embed it into Excel.
    When you have the SQL Drill main form open, and have a query setup, you should see an "Embed" button. The button will only get enabled when you have a name in the text box.. You can hit the button and embed the query into an excel sheet.

    After that you could add say a button to the sheet.

    Then, a good thing to do would be to setup an Excel "Named Range" and associate with the range where you have the embedded query. When I do this I typically use the top left hand corner of the range. Not necessary but it makes it a bit simpler to maintain the sheet I think.

    Lastly you could add in a VBA macro and associate it with the button.
    A simple macro is shown below. This will the embedded query that is in the same range area as the "QUERY1_RANGE".. So the "QUERY1_RANGE" is just a named range that is (say) in the top left hand corner of the area/range where you have your embedded query..

    [highlight=VBA]
    Sub RefreshQuery1Data()
    Range("QUERY1_RANGE").Select
    Selection.ListObject.QueryTable.Refresh BackgroundQuery:=False
    End Sub
    [/highlight]

    Hope this will be of some help to you. There are a bunch of ways to do this but this is one way that can be very good.
    Have a nice night
    Al
    SQL Drill Support
    www.sqldrill.com


  3. #3
    Andrea is offline Junior Member
    Join Date
    Jul 2009
    Posts
    6

    Default

    Hi Al,
    Thanks! I was able to embed the data into the worksheet.
    Now I am having trouble with the button and the macro.
    It is giving me errors, I am sure I am not doing it correctly, the names or something.
    Another thing, the results that I get when I update the query will vary, for example, I can have 24 rows one time and then when I update it in 20 min. I can have 54 rows. Does this matter when selecting the Range for the button?
    Can you help me a little more with the button and macro?? I really have no idea.

    Thanks again,
    Andrea.

  4. #4
    admin's Avatar
    admin is offline Administrator
    Join Date
    Apr 2008
    Location
    Dublin, NYC
    Posts
    333
    Blog Entries
    1

    Default

    Hi
    Hope all is good.

    Is the refresh working fine when you manually do it ? I mean if you right click within the table area and select "Refresh" from the short cut menu..

    If this is working fine then you could just record a macro to do it. So turn on the macro recorder, run the manual refresh and then stop the recorder. Then you could take a look at the VBA to see how to do it. The macro recorder is great for this type of situation. Once you have macro working fine you can attach it to the button..

    For the number of rows being returned. That should not be a problem as there are some settings there that can let you control how the data gets pasted in (if you clear out previously pasted data etc..). If you right click in a table area that has an embedded query, you will see a "Data Range Properties" entry that will load the form show below. Towards the end of the form you have some options that let you specify an option that will "Overwrite existing cells with new data, clear unused cells".. This will do what you want I think (in Excel 2007, I think the "Data Range Properties" is visible within the "Table" short cut item..)

    Hope this will get you going. Let me know how it goes when you get a chance. Good luck on that. Al


    SQL Drill Support
    www.sqldrill.com


  5. #5
    Andrea is offline Junior Member
    Join Date
    Jul 2009
    Posts
    6

    Default Thanks!

    Hey Al, thanks for the info!
    I was able to record the macro and made sure it woked fine. However, when I add a button, it does not work. Here's what I'm doing:
    Developer -> Insert -> Form Control & choose button ( i don't know if I should be choosing the button from the "Form Controls" menu or the "ActiveX Controls" (I don't really know the difference or when to use each one. So I chose the Forms Control. When I draw the button, a list of the macros come up & I select the one I just created. When I click on the button to test it, I get an error, I tryed to add a file with a pic. of the error screen but couldn't.
    This is the error I get:
    "Run-time error '1004':
    Application-defined or object defined error.
    When I click in the debug option, I get the following in the VBA window.

    Sub Update_Current_Query()
    '
    ' Update_Current_Query Macro

    Selection.QueryTable.Refresh BackgroundQuery:=False
    End Sub

    With the Selction. ..... line highlighted.

    Thanks again for your time & help!
    -Andrea

  6. #6
    admin's Avatar
    admin is offline Administrator
    Join Date
    Apr 2008
    Location
    Dublin, NYC
    Posts
    333
    Blog Entries
    1

    Default

    Hi Andrea

    It sounds like the macro is not recorded into the same sheet that has the embedded query (there is an option when you are recording a macro to determine where the macro will go..).

    If this is the problem then you could fix it by re-recording the macro - but making sure that you record it into the sheet where you have the embedded query.

    Another way would be to add the following like in to the top of the macro (you need to make sure that the workbook and worksheet where the embedded query is, is activated.. The line below should do this. You just need to change the workbook and worksheet name to refer to what you have..).
    [highlight=VBA]
    Workbooks("Book1").Worksheets("Sheet1").Activate
    [/highlight]

    I hope that gets you going.
    Have a nice night.
    Al
    SQL Drill Support
    www.sqldrill.com


Tags for this Thread

Bookmarks

Posting Permissions

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