473,394 Members | 1,759 Online
Bytes | Software Development & Data Engineering Community
Post Job

Home Posts Topics Members FAQ

Join Bytes to post your question to a community of 473,394 software developers and data experts.

user designed function not found

wa7gh
3
I have written a function that uses a user defined type. Here is the type

Expand|Select|Wrap|Line Numbers
  1. Option Compare Database
  2.  
  3. Public Type ProcessGender
  4.    additionalFemales As Double
  5.    additionalMales As Double
  6.  End Type
The function looks like this.
Expand|Select|Wrap|Line Numbers
  1. Option Compare Database
  2. Option Explicit
  3.  
  4.  
  5. Public Function genderCount(ethnicity As String, awardLevel As String) As ProcessGender
  6.  
  7.     Dim db As Database
  8.     Dim rs As DAO.Recordset
  9.     Dim strSQLString As String
  10.     Dim iFemaleCount As Double
  11.     Dim iMaleCount As Double
  12.     Dim iTotalCount As Double
  13.     Dim iUnknownCount As Integer
  14.     Dim iNewFemaleCount As Long
  15.     Dim iNewMaleCount As Double
  16.     Dim dPercentFemale As Double
  17.  
  18.  
  19.     Set db = CurrentDb()
  20.     strSQLString = "SELECT COUNT(*) FROM [CStep  9:  Completers By Level] WHERE sex =  ""F"" "
  21.     strSQLString = strSQLString + " AND converted_Eth_Orig = " '" + ethnicity + "' "
  22.     If CInt(awardLevel) > 0 Then
  23.        strSQLString = strSQLString + " AND award_level = " '" + awardLeve + "' "
  24.     End If
  25.     Set rs = db.OpenRecordset(strSQLString)
  26.     rs.MoveFirst
  27.     iFemaleCount = rs.Fields(0)
  28.     rs.Close
  29.     strSQLString = "SELECT COUNT(*) FROM [Step  9:  Completers By Level] WHERE sex = ""M"" "
  30.     strSQLString = strSQLString + " AND converted_Eth_Orig = " '" + ethnicity + "' "
  31.     If CInt(awardLevel) > 0 Then
  32.        strSQLString = strSQLString + " AND award_level = " '" + awardLeve + "' "
  33.     End If
  34.     Set rs = db.OpenRecordset(strSQLString)
  35.     iMaleCount = rs.Fields(0)
  36.     rs.Close
  37.     strSQLString = "SELECT COUNT(*) FROM [Step  9:  Completers By Level] WHERE sex IS NULL "
  38.     strSQLString = strSQLString + " AND converted_Eth_Orig = " '" + ethnicity + "' "
  39.     If CInt(awardLevel) > 0 Then
  40.        strSQLString = strSQLString + " AND award_level = " '" + awardLeve + "' "
  41.     End If
  42.     Set rs = db.OpenRecordset(strSQLString)
  43.     rs.MoveFirst
  44.     iUnknownCount = rs.Fields(0)
  45.     rs.Close
  46.     iTotalCount = iFemaleCount + iMaleCount + iUnknownCount
  47.     dPercentFemale = iFemaleCount / iTotalCount
  48.     iNewFemaleCount = iUnknownCount * dPercentFemale
  49.     iNewFemaleCount = CInt(iNewFemaleCount * 10) / 10
  50.     iNewMaleCount = iUnknownCount - iNewFemaleCount
  51.     db.Close
  52.  
  53.     genderCount.additionalFemales = iNewFemaleCount
  54.     genderCount.additionalMales = iNewMaleCount
  55.  
  56. End Function
and I'm calling it like this

Expand|Select|Wrap|Line Numbers
  1. SELECT Title, AYR, sex, ipeds_title, 
  2. SWITCH
  3.    sex = "M", COUNT(dw_key) + [GenderCount(converted_eth_orig)].additionalMale,
  4.    sex = "F",  COUNT(dw_key) + [GenderCount(converted_eth_orig)].additionalFemale
  5. ) AS TotalCount
  6. FROM [Step  9:  Completers By Level] AS c INNER JOIN (SELECT DISTINCT ipedsRaceCode, ipeds_title FROM newRaceCodes)  AS r ON r.ipedsRaceCode = c.converted_eth_orig
  7. GROUP BY Title, ayr, ipeds_title, sex
  8. ORDER BY Title, ayr, ipeds_title, sex;
When I try to run the query I get "Enter Parameter Value" box specifying the function call

For testing I created another module with the same code without the parameters. I hard coded those variables in my test code. It compiles and runs.

Then I created a macro to run the function. When I select RUNCODE and am prompted for the function to run, my function name comes up in the drop down box, so at that point Access can see the function.

When I try to run the macro I get "The expression you entered has a function name that Microsoft Access can't find.

I have renamed my module and function name to make sure there aren't any conflicts that I can see. I've tried doing a compact/repair and decompiling the database.
I am running in Access 2010 using an accdb file.

I have spent my afternoon Googling for a solution, and tried everything I have found.

I would very much appreciate any suggestions.

Thanks in advance
Sep 21 '12 #1

✓ answered by Rabbit

After some testing, I think you may have to do just that. You could use an additional parameter to tell the function which of the two values to return.

4 2034
Rabbit
12,516 Expert Mod 8TB
Please use code tags when posting code.

Don't put those square brackets around the function call. When you put square brackets around something, it demarcates it as a field or table name, it's not going to see it as a function.
Sep 21 '12 #2
wa7gh
3
Thanks Rabbit. I only put those around to get past another error. Without the square brackets I am getting

Invalid use of '.', '!', or '()'. in query expression 'GenderCount(converted_eth_orig,"0").additionalMal e'

.additionalMale gets populated in the function. It is a member of a user defined type I created so I could return two values. Maybe I will try passing in the gender and having the function just return an integer.
Sep 24 '12 #3
Rabbit
12,516 Expert Mod 8TB
After some testing, I think you may have to do just that. You could use an additional parameter to tell the function which of the two values to return.
Sep 24 '12 #4
wa7gh
3
That's what I'm doing and it is running. I think it is going to be slow, but at least I will get the answer.

Thanks Rabbit.
Sep 24 '12 #5

Sign in to post your reply or Sign up for a free account.

Similar topics

2
by: Steve D | last post by:
I've looked all over but can't find a solid answer. I've got a function that runs from a View and when the function runs the first time it is calculating a Temperature for a group of Formulas. ...
3
by: Gary Besta | last post by:
I am trying to add a simple case statement to a stored procedure or user defined function. However when I try and save the function/procedure I get 2 syntax errors. Running the query in query...
13
by: Maroon | last post by:
Hi, I want to write a standard java user defined function, like this example:- select db_fun("roll"), roll from student; **db_fun() will work for all tables of the all databse here db_fun is...
1
by: David Carwile | last post by:
I want to add a user defined function inside of an SQL string. I am using the function to change a group of numbers in a string to a specific format that can be sorted by Access(utilizing 0s). ...
6
by: Greg Strong | last post by:
Hello All, In an 'Update' query can you use user-defined functions in the 'Update To' for the query? Either no or I'm missing something. See the additional info below. If I run a query...
1
by: Mphoza | last post by:
Hi! Programmers,,,,,, Scenario I have a DataGrid with the delete button, If the user delete the row I'd like to show a confirmation dialog box with two buttons(Yes,No). If the user click yes...
3
by: chreo | last post by:
I have user-defined function in MSSQL which returns Table (with 10 columns) (sorry for Polish names) CREATE FUNCTION PACZKI_Z_AKCJI (@AKCJA_ID int) RETURNS TABLE RETURN SELECT TOP 100...
6
by: karthi | last post by:
hi, I need user defined function that converts string to float in c. since the library function atof and strtod occupies large space in my processor memory I can't use it in my code. regards,...
6
by: JLupear | last post by:
I have written a code (a translation of my first one) that is not working. I did a user defined function that is used on 'onsubmit'. It should total the value from the form selections and...
1
by: qwedster | last post by:
Hola! In the following code snippet, I am creating User Defined Function (T-SQL) programmatically into database from C# Code: BTW, this code originally I wrote for creating StoredProcedure...
0
by: Charles Arthur | last post by:
How do i turn on java script on a villaon, callus and itel keypad mobile phone
1
by: nemocccc | last post by:
hello, everyone, I want to develop a software for my android phone for daily needs, any suggestions?
1
by: Sonnysonu | last post by:
This is the data of csv file 1 2 3 1 2 3 1 2 3 1 2 3 2 3 2 3 3 the lengths should be different i have to store the data by column-wise with in the specific length. suppose the i have to...
0
marktang
by: marktang | last post by:
ONU (Optical Network Unit) is one of the key components for providing high-speed Internet services. Its primary function is to act as an endpoint device located at the user's premises. However,...
0
by: Hystou | last post by:
Most computers default to English, but sometimes we require a different language, especially when relocating. Forgot to request a specific language before your computer shipped? No problem! You can...
0
Oralloy
by: Oralloy | last post by:
Hello folks, I am unable to find appropriate documentation on the type promotion of bit-fields when using the generalised comparison operator "<=>". The problem is that using the GNU compilers,...
0
jinu1996
by: jinu1996 | last post by:
In today's digital age, having a compelling online presence is paramount for businesses aiming to thrive in a competitive landscape. At the heart of this digital strategy lies an intricately woven...
0
by: Hystou | last post by:
Overview: Windows 11 and 10 have less user interface control over operating system update behaviour than previous versions of Windows. In Windows 11 and 10, there is no way to turn off the Windows...
0
tracyyun
by: tracyyun | last post by:
Dear forum friends, With the development of smart home technology, a variety of wireless communication protocols have appeared on the market, such as Zigbee, Z-Wave, Wi-Fi, Bluetooth, etc. Each...

By using Bytes.com and it's services, you agree to our Privacy Policy and Terms of Use.

To disable or enable advertisements and analytics tracking please visit the manage ads & tracking page.