Search code examples
vbams-accesspass-through

Variable Inside the Access Pass Through Query


I set a global variable in my program.

public this_is_global_var as integer

this_is_global_var=1

Then I use that variable inside my pass through query

Select * from oracle_table where id=this_is_global_var ;

But error shows "this_is_global_var: invalid identifier"

Please help.Thanks.


Solution

  • You can define placeholders for variable inside the query definition and replace it before execution.

    qdfTemp.SQL = Replace(qdfMyQuery.SQL, "[this_is_global_var]", str(this_is_global_var))
    

    and then execute temp query. Original query will be untouched.