Excel recorded SQL database query not working -


i've recorded macro query database, , when record macro, query runs properly. however, when try run macro again on same sheet or on different one, error:

runtime error 1004, "sql syntax error"

on line

.refresh backgroundquery:=false".   

below recorded macro.

sub macro3()      activesheet.querytables.add(connection:= _         "odbc;dsn=substation prod;srvr=subp;uid=u326357;",     destination:=range("a1"))         .commandtext = array( _         "select fact_monthly.time_stamp, fact_monthly.system_number_val0, fact_monthly.substation_number_val0, fact_monthly.mva_max_out_val0, fact_monthly.mw_max_out_val0, fact_monthly.mvar_max_out_val0, fact_" _         , _         "monthly.mw_min_out_val0, fact_monthly.mvar_min_out_val0, fact_monthly.pf_max_val0, fact_monthly.pf_min_val0, fact_monthly.top_oil_tank_max_val0, fact_monthly.load_factor_val0, fact_monthly.ph1_tap_max" _         , _         "_drag_val0, fact_monthly.wind_temp_max_val0, fact_monthly.ltc_temp_max_val0, fact_monthly.ph2_tap_max_drag_val0, fact_monthly.ph3_tap_max_drag_val0, fact_monthly.bot_oil_temp_max_val0, fact_monthly.ph" _         , _         "1_tap_min_drag_val0, fact_monthly.ph2_tap_min_drag_val0, fact_monthly.ph3_tap_min_drag_val0, fact_monthly.ph1_load_max_kv_val0, fact_monthly.ph2_load_max_kv_val0, fact_monthly.ph3_load_max_kv_val0, fa")         .name = "query substation prod"         .fieldnames = true         .rownumbers = false         .filladjacentformulas = false         .preserveformatting = true         .refreshonfileopen = false         .backgroundquery = true         .refreshstyle = xlinsertdeletecells         .savepassword = false         .savedata = true         .adjustcolumnwidth = true         .refreshperiod = 0         .preservecolumninfo = true         .refresh backgroundquery:=false     end end sub 

i've searched online ways fix issue, none of other solutions i've found working. appreciated.

all previous lines inside statement setting properties.

.refresh backgroundquery := false  

is method call.

the refresh supposed refresh results. background query when quering sql data , optional think can leave off , have .refresh

for further assistance try vba excel querytables.add .refresh backgroundquery error


Comments

Popular posts from this blog

javascript - Using jquery append to add option values into a select element not working -

Android soft keyboard reverts to default keyboard on orientation change -

Rendering JButton to get the JCheckBox behavior in a JTable by using images does not update my table -