Reply
 
LinkBack Thread Tools Search this Thread Display Modes
  #1   Report Post  
Posted to microsoft.public.excel.programming
external usenet poster
 
Posts: 1
Default Reference Class Module in Access from Excel

I have created a custom function in Access. I used the Class Module
method as I wanted it to be accessible to Excel. I have this in a class
module in access;
Code:

Option Compare Database

Public Property Get strFinancialYear() As String
myDate = Date - 1
myYear = Year(myDate) - myYearModifier ' Get the year for
yesterday, with our modifier
If (MONTH(myDate)) = 4 Then ' If we are after april, this year is
first part of FN year
strFinancialYear = myYear & "/" & Right(myYear + 1, 2)
Else
strFinancialYear = myYear - 1 & "/" & Right(myYear, 2)
End If
End Property

Public Function FinancialYear() As String
FinancialYear = Me.strFinancialYear
End Function

This is then called from a module in access;

Function ReportingYear() As String
Dim myReportingYear As New CFinancialYear
ReportingYear = myReportingYear.strFinancialYear
End Function

I then have

ReportingYear()

In a query field to give "2005/06". This works fine. However, when I
try to access this same query from Excel, I get the following error;

[Microsoft][ODBC Microsoft Access Driver] Undefined function
'ReportingYear' in expression

In my references dialog in Excel, I have ticked;

Visual Basic for Applications
Microsoft Excel 10.0 Object Library
Microsoft Forms 10.0 Object Library
Microsoft Access 10.0 Object Library


I cannot find a reference for ODBC anywhere and I have tried ticking as
many references which might seem to be relevant, but I am getting
nowhere. Can anyone see what I am doing wrong as I don't seem to be
able to get anywhere on this I have been trying to get this working for
months now and its becoming very frustrating.

  #2   Report Post  
Posted to microsoft.public.excel.programming
external usenet poster
 
Posts: 1,163
Default Reference Class Module in Access from Excel

No need to add a reference for ODBC; you are already using ODBC (when you
query Access). In fact, the error you are getting is being sent from the
ODBC driver. I know the reason but no easy solution. I assume you are using
either MSQuery or ADO to get your Access data; both of these convert the
query to SQL. Now, while your Access project understands your functions the
SQL interpreter doesn't, thus the error. The easiest thing I can think of is
to omit that field from your query and duplicate it in an Excel function.
But that can lead to frustration down the road if you change it 5 years from
now and forget that it also needs to be changed in Excel. A potentially
better method would be to add a reference to MSAccess to your Excel project
and actually open the database and manipulate it directly via automation.

There maybe a way of using custom functions in an external database query
that I don't know of so you may need to research this further.
--
- K Dales


" wrote:

I have created a custom function in Access. I used the Class Module
method as I wanted it to be accessible to Excel. I have this in a class
module in access;
Code:

Option Compare Database

Public Property Get strFinancialYear() As String
myDate = Date - 1
myYear = Year(myDate) - myYearModifier ' Get the year for
yesterday, with our modifier
If (MONTH(myDate)) = 4 Then ' If we are after april, this year is
first part of FN year
strFinancialYear = myYear & "/" & Right(myYear + 1, 2)
Else
strFinancialYear = myYear - 1 & "/" & Right(myYear, 2)
End If
End Property

Public Function FinancialYear() As String
FinancialYear = Me.strFinancialYear
End Function

This is then called from a module in access;

Function ReportingYear() As String
Dim myReportingYear As New CFinancialYear
ReportingYear = myReportingYear.strFinancialYear
End Function

I then have

ReportingYear()

In a query field to give "2005/06". This works fine. However, when I
try to access this same query from Excel, I get the following error;

[Microsoft][ODBC Microsoft Access Driver] Undefined function
'ReportingYear' in expression

In my references dialog in Excel, I have ticked;

Visual Basic for Applications
Microsoft Excel 10.0 Object Library
Microsoft Forms 10.0 Object Library
Microsoft Access 10.0 Object Library


I cannot find a reference for ODBC anywhere and I have tried ticking as
many references which might seem to be relevant, but I am getting
nowhere. Can anyone see what I am doing wrong as I don't seem to be
able to get anywhere on this I have been trying to get this working for
months now and its becoming very frustrating.


  #3   Report Post  
Posted to microsoft.public.excel.programming
external usenet poster
 
Posts: 1
Default Reference Class Module in Access from Excel

Thanks for the reply K, thats helped my understanding of the problem. I
think the best route to go down would be to replicate the function in
Excel. The exporting to excel is a seperate function from anything else
used in the database, so it should work out better than the method I am
currently using. Again, thanks for the reply.

Reply
Thread Tools Search this Thread
Search this Thread:

Advanced Search
Display Modes

Posting Rules

Smilies are On
[IMG] code is On
HTML code is Off
Trackbacks are On
Pingbacks are On
Refbacks are On


Similar Threads
Thread Thread Starter Forum Replies Last Post
How to reference a Class Module located in an add-in or another workbook? keithb Excel Programming 1 September 10th 05 01:40 AM
Excel ActiveX causes lost Class Module reference Jason Webley Excel Programming 2 May 30th 05 11:43 AM
How can I name the Module or class after I insert it into the Excel new.microsoft.com Excel Programming 2 January 17th 04 04:18 AM
Exposing Class Module from VBA Excel 97 SR-2 hakim Excel Programming 3 November 5th 03 05:54 PM
Variable from a sheet module in a class module in XL XP hglamy[_2_] Excel Programming 2 October 14th 03 05:48 PM


All times are GMT +1. The time now is 10:36 AM.

Powered by vBulletin® Copyright ©2000 - 2025, Jelsoft Enterprises Ltd.
Copyright ©2004-2025 ExcelBanter.
The comments are property of their posters.
 

About Us

"It's about Microsoft Excel"