LinkBack Thread Tools Search this Thread Display Modes
Prev Previous Post   Next Post Next
  #1   Report Post  
Posted to microsoft.public.excel.programming
external usenet poster
 
Posts: 2
Default Changing fixed date with a variable in a ODBC Query

Below is the original code we use in our VB to retrieve
data directly from database. Instead of using a fixed
activation date "2003-09-17 00:00:00" (please check the
location in the code below) we want to replace that with
a variable where it makes the code more flexible such as
Temp1 where we enter or define the date to Temp1 earlier
in the code. We would appreciate if someone could help
us with the syntax.

Actual Code
-----------

With ActiveSheet.QueryTables.Add(Connection:= _
"ODBC;DRIVER=SQL
Server;SERVER=AAA_BBBBBBB;UID=TTTTTTT;PWD=TTTTTTT; APP=Micr
osoft Office XP;WSID=TTTTTTT;DATABASE=reports" _
, Destination:=Range("A1"))
.CommandText = Array( _
"SELECT Controlling_stop_invoice.Contract,
Controlling_stop_invoice.A,
Controlling_stop_invoice.Currency,
Controlling_stop_invoice.Payment_Due_Date,
Controlling_stop_invoice.Debt_ID, Controlling_stop_i" _
, _
"nvoice.Principal,
Controlling_stop_invoice.Activation_Date,
Controlling_stop_invoice.Units,
Controlling_stop_invoice.Vehicle_Group" & Chr(13) & "" &
Chr(10) & "FROM reports.dbo.Controlling_stop_invoice
Controlling_stop_invoice" & Chr(13) & "" & Chr(10) & "" _
, _
"WHERE (Controlling_stop_invoice.Debt_ID='21')
AND (Controlling_stop_invoice.Activation_Date<={ts '2003-
09-17 00:00:00'})" & Chr(13) & "" & Chr(10) & "ORDER BY
Controlling_stop_invoice.Contract" _
)
.Name = "Query from reports_ok_20"
.FieldNames = True
.RowNumbers = False
.FillAdjacentFormulas = False
.PreserveFormatting = True
.RefreshOnFileOpen = False
.BackgroundQuery = True
.RefreshStyle = xlInsertDeleteCells
.SavePassword = True
.SaveData = True
.AdjustColumnWidth = True
.RefreshPeriod = 0
.PreserveColumnInfo = True
.Refresh BackgroundQuery:=False
End With
 
Thread Tools Search this Thread
Search this Thread:

Advanced Search
Display Modes

Posting Rules

Smilies are On
[IMG] code is On
HTML code is Off
Trackbacks are On
Pingbacks are On
Refbacks are On


Similar Threads
Thread Thread Starter Forum Replies Last Post
ODBC Query Laddie Excel Worksheet Functions 0 April 23rd 10 03:35 PM
Microsoft Query is changing a negative number into a date mowens Excel Discussion (Misc queries) 1 March 10th 10 06:20 PM
Changing ODBC data source for a query embedded in Excel Matt Colegrove Excel Discussion (Misc queries) 4 June 15th 07 01:04 AM
Changing data source on ODBC query Aussie CPA Excel Discussion (Misc queries) 2 June 14th 07 05:44 PM
Changing ODBC link in a query Keith Excel Discussion (Misc queries) 0 June 13th 07 02:27 PM


All times are GMT +1. The time now is 05:05 AM.

Powered by vBulletin® Copyright ©2000 - 2024, Jelsoft Enterprises Ltd.
Copyright ©2004-2024 ExcelBanter.
The comments are property of their posters.
 

About Us

"It's about Microsoft Excel"