VB criteria for SQL(Query) parameter driven

aka_krakur

Active Member
Joined
Jan 31, 2006
Messages
438
I have a VB that invokes an Excel Query
the entire script works up until the parameter I need.

Code:
With ActiveSheet.QueryTables.Add(Connection:=Array(Array( _
        "ODBC;DSN=DBNAME;UID=USER;PWD=PASSWORD;DBQ=DBNAME;DBA=W;APA=T;EXC=F;FEN=T;QTO=T;FRC=10;FDL=10;LOB=T;RST=T;GDE=F;FRL=F;BAM" _
        ), Array("=IfAllSuccessful;MTS=F;MDI=F;CSR=F;FWC=F;PFC=10;TLO=0;")), _
        Destination:=Range("A4"))
        .CommandText = Array( _
"SELECT {LONG LIST OF FIELDS HERE - IRRELEVANT} " _
FROM {list of tables} " _
Where {list of joins} " _
and table.date >= " & Range("B1") " _
)
.Name = "Query from DBNAME"
        .FieldNames = False
        .RowNumbers = False
        .FillAdjacentFormulas = True
        .PreserveFormatting = True
        .RefreshOnFileOpen = False
        .BackgroundQuery = True
        .RefreshStyle = xlOverwriteCells
        .SavePassword = True
        .SaveData = True
        .AdjustColumnWidth = False
        .RefreshPeriod = 0
        .PreserveColumnInfo = True
        .Refresh BackgroundQuery:=False
    End With
I am trying to run the above query when the user inputs a new date in cell B1.
Oracle DB is specific to need the format of the date parameter to be 'DD-MMM-YYYY'
When I remove the parameter and physically type '01-AUG-2011' AFTER the table.date >=
the VB works.
Any idea what I might be doing wrong?
 

Excel Facts

VLOOKUP to Left?
Use =VLOOKUP(A2,CHOOSE({1,2},$Z$1:$Z$99,$Y$1:$Y$99),2,False) to lookup Y values to left of Z values.
Just a guess ...

Code:
... table.date >= " & Range("B1")[COLOR=Red].Text[/COLOR]

Maybe it's defaulting to .Value and passing a serial number?

Gary
 
Upvote 0

Forum statistics

Threads
1,224,586
Messages
6,179,719
Members
452,939
Latest member
WCrawford

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