Modify Query Parameters with VBA

robertokalos

New Member
Joined
Nov 29, 2011
Messages
5
I would like to be able modify my query parameters by using VBA.

The VBA I recorded is:

With Selection.QueryTable
.Connection = _
"ODBC;DRIVER={AR System ODBC Driver};ARServer=HAYDN;UID=harvanek;PWD=dorotka5;ARAuthentication=;SERVER=NotTheServer"
.CommandText = Array( _
"SELECT ""CR-Ticket"".Application, ""CR-Ticket"".""Business Priority"", ""CR-Ticket"".Item, ""CR-Ticket"".""Request Date"", ""CR-Ticket"".Department, ""CR-Ticket"".""Requested by"", ""CR-Ticket"".""Service Type"", ""CR-Ticke" _
, _
"t"".""CR ID"", ""CR-Ticket"".Status, ""CR-Ticket"".""Assigned To"", ""CR-Ticket"".""Closed Date"", ""CR-Ticket"".Priority, ""CR-Ticket"".Phase, ""CR-Ticket"".""Target Release"", ""CR-Ticket"".Module, ""CR-Ticket"".Entity" & Chr(13) & "" & Chr(10) & "FRO" _
, _
"M ""CR-Ticket"" ""CR-Ticket""" & Chr(13) & "" & Chr(10) & "WHERE (""CR-Ticket"".Item In ('Borrowings','Treasury')) AND (""CR-Ticket"".Status<>'Rejected' And ""CR-Ticket"".Status<>'Closed') AND (""CR-Ticket"".Entity='Finance+Risk') AND (""CR-" _
, _
"Ticket"".""Request Date""<={ts '2011-10-31 00:00:00'})" & Chr(13) & "" & Chr(10) & "ORDER BY ""CR-Ticket"".""Service Type"" DESC, ""CR-Ticket"".Status, ""CR-Ticket"".""Assigned To"", ""CR-Ticket"".""CR ID""" _
)
End With


The field of the query I want to be able to modify is the date (=2011-10-31). I would like to be able to use different dates. The input of the day could be a cell in the excel file.

Please Help me!!!!
 

Excel Facts

What is the last column in Excel?
Excel columns run from A to Z, AA to AZ, AAA to XFD. The last column is XFD.
Try this (untested). Assumes the date is in cell A1 of the active sheet.
Code:
With Selection.QueryTable
    .Connection = _
    "ODBC;DRIVER={AR System ODBC Driver};ARServer=HAYDN;UID=harvanek;PWD=dorotka5;ARAuthentication=;SERVER=NotTheServer"
    .CommandText = Array( _
    "SELECT ""CR-Ticket"".Application, ""CR-Ticket"".""Business Priority"", ""CR-Ticket"".Item, ""CR-Ticket"".""Request Date"", ""CR-Ticket"".Department, ""CR-Ticket"".""Requested by"", ""CR-Ticket"".""Service Type"", ""CR-Ticke" _
    , _
    "t"".""CR ID"", ""CR-Ticket"".Status, ""CR-Ticket"".""Assigned To"", ""CR-Ticket"".""Closed Date"", ""CR-Ticket"".Priority, ""CR-Ticket"".Phase, ""CR-Ticket"".""Target Release"", ""CR-Ticket"".Module, ""CR-Ticket"".Entity" & Chr(13) & "" & Chr(10) & "FRO" _
    , _
    "M ""CR-Ticket"" ""CR-Ticket""" & Chr(13) & "" & Chr(10) & "WHERE (""CR-Ticket"".Item In ('Borrowings','Treasury')) AND (""CR-Ticket"".Status<>'Rejected' And ""CR-Ticket"".Status<>'Closed') AND (""CR-Ticket"".Entity='Finance+Risk') AND (""CR-" _
    , _
    "Ticket"".""Request Date""<={ts '" & Format(Range("A1").Value, "yyyy-mm-dd 00:00:00") & "'})" & Chr(13) & "" & Chr(10) & "ORDER BY ""CR-Ticket"".""Service Type"" DESC, ""CR-Ticket"".Status, ""CR-Ticket"".""Assigned To"", ""CR-Ticket"".""CR ID""" _
    )
End With
 
Upvote 0

Forum statistics

Threads
1,215,365
Messages
6,124,513
Members
449,168
Latest member
CheerfulWalker

We've detected that you are using an adblocker.

We have a great community of people providing Excel help here, but the hosting costs are enormous. You can help keep this site running by allowing ads on MrExcel.com.
Allow Ads at MrExcel

Which adblocker are you using?

Disable AdBlock

Follow these easy steps to disable AdBlock

1)Click on the icon in the browser’s toolbar.
2)Click on the icon in the browser’s toolbar.
2)Click on the "Pause on this site" option.
Go back

Disable AdBlock Plus

Follow these easy steps to disable AdBlock Plus

1)Click on the icon in the browser’s toolbar.
2)Click on the toggle to disable it for "mrexcel.com".
Go back

Disable uBlock Origin

Follow these easy steps to disable uBlock Origin

1)Click on the icon in the browser’s toolbar.
2)Click on the "Power" button.
3)Click on the "Refresh" button.
Go back

Disable uBlock

Follow these easy steps to disable uBlock

1)Click on the icon in the browser’s toolbar.
2)Click on the "Power" button.
3)Click on the "Refresh" button.
Go back
Back
Top