State of the question:
I no longer think it is relevant that I'm referencing Excel or that the query has parameters. I think question boils down to this: How can I use an Access query which uses Access-VBA-defined functions in Word VBA?
What I want to do is impossible, how can I make an inlined version of the Acos function work with my query, as per shahkalpesh's answer?
I have a function in Access VBA:
Public Function Acos(radians As Double) As Double
Acos = WorksheetFunction.Acos(radians)
End Function
WorksheetFunction
is coming from referencing Excel (which I do simply because it defines the acos function).
I use this function in a query that has three parameters. Then I run this query in Word VBA as follows:
Dim command As New ADODB.command
With command
.ActiveConnection = connection
.CommandText = "MyQueryName"
.CommandType = adCmdStoredProc
.Parameters.Append .CreateParameter( _
"Param1", adDouble, adParamInput, , param1Value)
.Parameters.Append .CreateParameter( _
"Param2", adDouble, adParamInput, , param2Value)
.Parameters.Append .CreateParameter( _
"Param3", adDouble, adParamInput, , param3Value)
End With
Dim records As New ADODB.Recordset
records.Open command, , adOpenKeyset, adLockOptimistic
I get an error in Word VBA that the function Acos is not defined.
Ideas?
UPDATE
In response to comment: Yes, the query works perfectly in Access.
Also, just a note, this is all Office 2007.
UPDATE 2
We are going from Access to Word because the VBA program is already in Word but needs to do some data crunching which it isn't really practical to do in VBA.
Changing to creating an Excel Application object has no effect aside from dramatically slowing down the query.
UPDATE 3
I have the reference to Excel in both Word and Access. (If there is a better way to get an acos function, I'm certainly open to it.)