View Single Post
  #9   Report Post  
Posted to microsoft.public.excel.programming
ivan ivan is offline
external usenet poster
 
Posts: 67
Default sql query in excel

Thanks for the info, the problem is i am working with remedy.
There i can use $date$ to replace the day but doesnt work in the microsoft
query

"DM Unseen" wrote:

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