View Single Post
  #3   Report Post  
Posted to microsoft.public.excel.programming
Jim Parsells Jim Parsells is offline
external usenet poster
 
Posts: 7
Default User Defined Function not allowed in Excel Query of Access DB?

Just a regular query from Excel. The query and function run as expected in
Access. I am not using CreateObject. If MSQuery would handle the use of the
Access function, there would be no VBA required in Excel.

The desired behavior is: In Excel-Create a PivotTable using an external data
source, the Query as defined in Access. Finish setting up the PivotTable. Be
able to simply Refresh data on the PivotTable as more data is added to the
AccessDB.
--
Jim Parsells


"Joel" wrote:

I'm not sure if you are just using Excel Queries or you are using an Access
object like

set obj = getobject(C:\temp\database.mdb")

I usually try to get the macro running 1st in the application they are using
and then convert the macro to excel.

"Jim Parsells" wrote:

Using Office 2003 Pro.
I wish to use a subset of data in an AccessDB Table as the data source for
an Excel PivotTable. This is normally easy and I have done it many times.
However, in this case one of the fields in the Table has several spellings
for the same entity. I need to generate a name mapping function to
standardize this field.
This is also simple. I define a VBA routine in Access to perform the mapping.
Now the Access Query has syntax (abbreviated here) like this:

SELECT AccountQuery.TransDate, NameMapper([AccountQuery]![Memo]) AS CurName,
...FROM AccountQuery ...

In this case, NameMapper is my VBA function defined in Access. Naturally, it
gives the proper results in Access.

Any reference, in Excel, to this Access Query fails complaining that
NameMapper is unknown.

I can work around this using VBA in Excel to perform the name mapping, but
that leads me to some fairly complex code in getting the PivotTable set up
and, more
difficult, to catching the PivotTable Refresh so that I can do the right
thing.

Before I get into that, I would like to know if there is a way to get
MSQuery to accept/use the Access VBA routine as defined in the Access Query?
In other words, I want to define the query in Access, using the name mapping
function, and then have Excel able to directly use that query as the data for
a PivotTable.

An alternative would be to get MSQuery to run the name mapping function as
defined in an Excel VBA module.

Since this one case is not too vital to me, I can work around it in other
ways, however, I can forsee other cases in which a user defined function in
Access would be very useful when used in a Access query providing data to
Excel.
--
Jim Parsells