PDA

View Full Version : [SOLVED] VBA Syntax to run sql statement with where and order by



jo15765
04-28-2016, 08:11 AM
I know how to connect to sql server and run a query. But for the life of me, I can not get the syntax correct for this statement. WHAT do I keep inputting incorrect?


strsql = "Select name from names where bday between "&A1&" AND "&A2&" Order BY name ASC"

JKwan
04-28-2016, 10:26 AM
try this:

strsql = "Select name from names where bday between " & Range("A1") & _
" AND " & Range("A2") & " Order BY name ASC"