调用MS Access查询,该查询从Delphi ADO组件调用模块中的VBA函数

问题描述:

我在MS Access Module中创建了一个函数,例如Calculate(A, B).

I created a function in an MS Access Module, let's say Calculate(A, B).

我还在MS Access中创建了一个查询以使用此功能,比如:

I also created a Query in MS Access to use this function, let's say:

UPDATE aTable 
SET aField = Calculate(bField, cField)

由于我尝试使用adoConnection.ExecuteadoTableadoQueryadoCommandStoredProcedure,因此如何调用查询,它们都拒绝并显示消息

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

谢谢.

您不能.

使用用户定义的VBA函数的查询只能由Access Application对象执行,并且只能通过DoCmd.OpenQueryDoCmd.RunSQL方法执行.

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.

相反,请使用COM和Access Application对象自动执行任务.请注意,这会导致可观的开销.或者,如果可能,请在SQL子句中进行计算.

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.

它们不能通过ODBC或OLEDB使用,因此在ADO中不可用.

They're not available through ODBC or OLEDB, thus not available in ADO.

如果没有完整版本的Access(不是运行时版本或数据库引擎),那么您将无法运行使用用户定义的VBA函数的查询.

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.