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

javascript - How to synchronize the Three.js and HTML/SVG coordinate systems (especially w.r.t. the y-axis)? -

javascript - How do I find how many occurences are there of a highlighted string, and which occurence is it? -

java - Reading data from multiple zip files and combining them to one -