View Single Post
  #8   Report Post  
Posted to microsoft.public.excel.programming
DM Unseen DM Unseen is offline
external usenet poster
 
Posts: 233
Default sql query in excel

There are 2 ways to solve this:

create a new column in your select clause that gives the current
day/time. The function to do this depends on the DBMS. e.g. for SQL
server this is "getdate()"

so "Select getdate() as CurrentDate, ...... from ...." would work on
SQL Server.

If your query gives more that 1 record you will see the date for each
line (maybe not want you want).

With VBA it would look something like this:

In Thisworkbook module:

Dim Withevents qtb as QueryTable

Sub Workbook_Open

Set qtb = Thisworkbook.Sheets("Mysheet").QueryTables("Mytabl e")

End Sub


qtb_AfterRefresh(bSuccess as boolean)

if bSuccess then Range("Mysheet!A1") = Now()

End Sub

This code would update A1 with current date after a succesful refresh.


DM Unseen