sql - Replacing multiple command text variables in OLEDB connection with cell value using VBA -


i still new vba , having bit of difficulty getting work. have connection in excel 2013 linked sql specific script in command text. wanting build vba macro allows me set date range script works on specific cell value.

example command text:

select [field name] [table name] [datefield] between [datestart] , [dateend] 

in above scenario, want set [datestart] = "e8" , [dateend] = "e9" how go doing that? of posts have read have said use microsoft query in order set parameters, computer doesn't seem support doing way.

you can use replace function since sql query string expression vba:

sqlstatement = "select [field name] [table name] [datefield] between [datestart] , [dateend]"  datestart = year(range("e8").value) & "-" & month(range("e8").value) & "-" & day(range("e8").value) dateend = year(range("e9").value) & "-" & month(range("e9").value) & "-" & day(range("e9").value)  sqlstatement = replace(sqlstatement, "[datestart]", datestart) sqlstatement = replace(sqlstatement, "[dateend]", dateend) 

Comments

Popular posts from this blog

python - mat is not a numerical tuple : openCV error -

c# - MSAA finds controls UI Automation doesn't -

wordpress - .htaccess: RewriteRule: bad flag delimiters -