Results 1 to 5 of 5

Thread: How to display and edit SQL query

  1. #1

    Thread Starter
    Hyperactive Member
    Join Date
    Apr 2002
    Posts
    382

    How to display and edit SQL query

    I have an Excel 2007 workbook that uses several data connections (SQL queries) to pull data from an Access database. I would like to display the SQL statement for a particular named connection (Msgbox is okay). Then I would like to edit the same connection using VBA. Please help with example VBA code. Thanks.

  2. #2
    PowerPoster
    Join Date
    Dec 2004
    Posts
    25,618

    Re: How to display and edit SQL query

    add a userform with a textbox, you can then display and edit your sql query, a command button to continue the code or execute the edited query

    could be a textbox in a worksheet, if you do not want a user form
    i do my best to test code works before i post it, but sometimes am unable to do so for some reason, and usually say so if this is the case.
    Note code snippets posted are just that and do not include error handling that is required in real world applications, but avoid On Error Resume Next

    dim all variables as required as often i have done so elsewhere in my code but only posted the relevant part

    come back and mark your original post as resolved if your problem is fixed
    pete

  3. #3

    Thread Starter
    Hyperactive Member
    Join Date
    Apr 2002
    Posts
    382

    Re: How to display and edit SQL query

    Thanks but I'd rather not use a user form. I don't want to change the operation of the report. I'd like to display certain parts of the query in the header of the report being created. Isn't there some way, within the VBA project of the workbook, to capture the text of the SQL command of a named data connection within that workbook?

  4. #4
    PowerPoster
    Join Date
    Dec 2004
    Posts
    25,618

    Re: How to display and edit SQL query

    within the VBA project of the workbook, to capture the text of the SQL command of a named data connection within that workbook?
    yes, but you asked to display and edit
    i do my best to test code works before i post it, but sometimes am unable to do so for some reason, and usually say so if this is the case.
    Note code snippets posted are just that and do not include error handling that is required in real world applications, but avoid On Error Resume Next

    dim all variables as required as often i have done so elsewhere in my code but only posted the relevant part

    come back and mark your original post as resolved if your problem is fixed
    pete

  5. #5

    Thread Starter
    Hyperactive Member
    Join Date
    Apr 2002
    Posts
    382

    Re: How to display and edit SQL query

    OK, so how do I use a text box to display the SQL statement of a certain 'Data Connection' query? Can you show a VBA code example? I really appreciate your help.

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