I have defined a procedure in my module, returning the path of the database and I want to use that path in my sql query.
Procedure in module :
Public Function pathOfBillingSoftware() As String pathOfBillingSoftware = """path""" End Function
I am using the function above in my sql query :
SELECT * FROM tableName IN pathOfBillingSoftware();
It is giving me the error: “error in from clause”
but when I am using it in vba code , it is working fine
a = pathOfBillingSoftware() sql = "INSERT INTO tableName " & _ "IN " & a & _ " SELECT * FROM tableName" currentdb.Execute sql
Any Solution ?
Advertisement
Answer
This is dynamic SQL. You seem to already have found the solution: use VBA code. You can only use functions to return values in static SQL.
If you want to return operators or other things that aren’t standard values, you need to use dynamic SQL, and thus need to use VBA.
You can create queries through VBA if you want, but note that once they are created, they are static.
Sample code to create a query with your function
CurrentDb.CreateQueryDef "MyQuery", "SELECT * FROM tableName IN " & pathOfBillingSoftware();