问题
I created a function in an MS Access Module, let's say Calculate(A, B).
I also created a Query in MS Access to use this function, let's say:
UPDATE aTable
SET aField = Calculate(bField, cField)
How can I invoke the query, since I tried using: adoConnection.Execute, adoTable, adoQuery, adoCommand, and StoredProcedure, all reject it with the message
Undefined function Calculate in expression
Thank you in advance.
回答1:
You can't.
Queries using user-defined VBA functions can only be executed by the Access Application object, and only through the DoCmd.OpenQuery and DoCmd.RunSQL methods.
Instead, use COM and the Access Application object to automate the task. Do note this will cause considerable overhead. Or, when possible, do the calculation in the SQL clause.
They're not available through ODBC or OLEDB, thus not available in ADO.
If the full version of Access (not runtime version or database engine) isn't available, you unfortunately can't run queries that use user-defined VBA functions.
来源:https://stackoverflow.com/questions/53478882/invoke-ms-access-query-which-calls-a-vba-function-in-a-module-from-delphi-ado-co