vba - Variable Table Name in SQL Server -


i've looked through forums , know question has been asked before, after trying has been suggested still can't work. i'm new both vba , sql explain why i'm struggling.

what i'm trying create form when executed runs query:

strsql = "select new.[service name], new.wbs, new.[billing code], new.[cpu units], new.[vcpu units], new.[billing status], new.[bill to] " & _  " " & strnew & " new left join " & strold & " old on new.[service name] = old.[service name] " & _  " old.[service name] null;" 

i created form , have stored user inputs both strnew , strold respectively. when execute code, receive error. i've confirmed values inputted form actual "tables" located in database. why not work? appreciate help.

i think trying create dynamic query, first advise can give you, need read erland sommarskog's article. in order solve problem is:

dim strnew string dim strold string  strsql = "select new.[service name], new.wbs, new.[billing code], new.[cpu units], new.[vcpu units], new.[billing status], new.[bill to]" & _ "from " & strnew & " new left join " & strold & " old on new.[service name] = old.[service name]" & _ "where old.[service name] null;" 

let know if code works you.


Comments

Popular posts from this blog

Android : Making Listview full screen -

javascript - Parse JSON from the body of the POST -

javascript - How to Hide Date Menu from Datepicker in yii2 -