+ Reply to Thread
Results 1 to 7 of 7

Using Worksheet as RecordSet

  1. #1
    Registered User
    Join Date
    12-17-2009
    Location
    Falls Church, VA, USA
    MS-Off Ver
    Excel 2003
    Posts
    4

    Using Worksheet as RecordSet

    Hi Folks,

    I have lots of occasions to use worksheets as database tables. As far as I know, the natural way to do this (correct me if I'm wrong) is to open an ADODB connection to the workbook, using the workbook's path.

    Please Login or Register  to view this content.
    However, this has a side effect, in that changes to the "table" worksheet aren't available until the workbook is saved down. I would like to query the worksheet and get the new data without having to save down first.

    So, the question is: Is there a way to use a worksheet as a table in ThisWorksheet so that it doesn't need to open an extra file connection (to an undesirably stale version of the workbook)?

    Thanks,
    Jamie

  2. #2
    Forum Moderator Leith Ross's Avatar
    Join Date
    01-15-2005
    Location
    San Francisco, Ca
    MS-Off Ver
    2000, 2003, & 2010
    Posts
    23,259

    Re: Using Worksheet as RecordSet

    Hello Jamie,

    I am not sure you can get around this. The ADODB connects to the saved workbook. When Excel opens, it creates a mirror copy that contains the current workbook changes. These changes aren't realized until the workbook is saved.
    Sincerely,
    Leith Ross

    Remember To Do the Following....

    1. Use code tags. Place [CODE] before the first line of code and [/CODE] after the last line of code.
    2. Thank those who have helped you by clicking the Star below the post.
    3. Please mark your post [SOLVED] if it has been answered satisfactorily.


    Old Scottish Proverb...
    Luathaid gu deanamh maille! (Rushing causes delays!)

  3. #3
    Registered User
    Join Date
    11-20-2009
    Location
    Raymond,WA
    MS-Off Ver
    Excel 2002
    Posts
    40

    Re: Using Worksheet as RecordSet

    Sorry - but I don't have a clear understanding of the situation.

    Are you calling this code from another Excel workbook?
    Is the datasource data potentially being changed by others?
    Are your changes what makes the data 'stale'?

  4. #4
    Registered User
    Join Date
    12-17-2009
    Location
    Falls Church, VA, USA
    MS-Off Ver
    Excel 2003
    Posts
    4

    Re: Using Worksheet as RecordSet

    Quote Originally Posted by Leith Ross View Post
    Hello Jamie,

    I am not sure you can get around this. The ADODB connects to the saved workbook. When Excel opens, it creates a mirror copy that contains the current workbook changes. These changes aren't realized until the workbook is saved.
    Okay, then I guess that settles it for ADODB. However, is there some other way that I don't know about to access a worksheet as a table in ThisWorkbook (i.e., the workbook being edited).

    Thanks,
    Jamie

  5. #5
    Registered User
    Join Date
    12-17-2009
    Location
    Falls Church, VA, USA
    MS-Off Ver
    Excel 2003
    Posts
    4

    Re: Using Worksheet as RecordSet

    Quote Originally Posted by TimK View Post
    Sorry - but I don't have a clear understanding of the situation.

    Are you calling this code from another Excel workbook?
    No, they are one and the same. (Caller=Called Workbook)
    Is the datasource data potentially being changed by others?
    No--not that I care about, anyway.
    Are your changes what makes the data 'stale'?
    Yes, exactly. *My* unsaved changes are what makes the (saved) data "stale."

    Thanks for asking,
    Jamie

  6. #6
    Valued Forum Contributor
    Join Date
    08-26-2006
    Location
    -
    MS-Off Ver
    2010
    Posts
    388

    Re: Using Worksheet as RecordSet

    Jamie - Maybe you are doing something different, but using VBA with an ADODB connection and simple SQL to create a recordset, I'm able to query a worksheet (table) of the current workbook and return the current data, without saving the workbook between changes to the data.

    Another way is to use Data > Import External Data, which creates a Querytable. This also doesn't need the workbook to be saved between data changes - just click the Refresh Data button on the External Data Toolbar.

  7. #7
    Registered User
    Join Date
    12-17-2009
    Location
    Falls Church, VA, USA
    MS-Off Ver
    Excel 2003
    Posts
    4

    Re: Using Worksheet as RecordSet

    Quote Originally Posted by T-J View Post
    Jamie - Maybe you are doing something different, but using VBA with an ADODB connection and simple SQL to create a recordset, I'm able to query a worksheet (table) of the current workbook and return the current data, without saving the workbook between changes to the data.

    Another way is to use Data > Import External Data, which creates a Querytable. This also doesn't need the workbook to be saved between data changes - just click the Refresh Data button on the External Data Toolbar.
    How does your code differ from the code in my first post? Mine only gets saved data.

    For instance, if I add a few "records" to the worksheet, they are not reflected in my query until I save down the workbook.

    Thanks,
    Jamie

+ Reply to Thread

Thread Information

Users Browsing this Thread

There are currently 1 users browsing this thread. (0 members and 1 guests)

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

Search Engine Friendly URLs by vBSEO 3.6.0 RC 1