Expand|Select|Wrap|Line Numbers
- Option Compare Database
- Public Type ProcessGender
- additionalFemales As Double
- additionalMales As Double
- End Type
Expand|Select|Wrap|Line Numbers
- Option Compare Database
- Option Explicit
- Public Function genderCount(ethnicity As String, awardLevel As String) As ProcessGender
- Dim db As Database
- Dim rs As DAO.Recordset
- Dim strSQLString As String
- Dim iFemaleCount As Double
- Dim iMaleCount As Double
- Dim iTotalCount As Double
- Dim iUnknownCount As Integer
- Dim iNewFemaleCount As Long
- Dim iNewMaleCount As Double
- Dim dPercentFemale As Double
- Set db = CurrentDb()
- strSQLString = "SELECT COUNT(*) FROM [CStep 9: Completers By Level] WHERE sex = ""F"" "
- strSQLString = strSQLString + " AND converted_Eth_Orig = " '" + ethnicity + "' "
- If CInt(awardLevel) > 0 Then
- strSQLString = strSQLString + " AND award_level = " '" + awardLeve + "' "
- End If
- Set rs = db.OpenRecordset(strSQLString)
- rs.MoveFirst
- iFemaleCount = rs.Fields(0)
- rs.Close
- strSQLString = "SELECT COUNT(*) FROM [Step 9: Completers By Level] WHERE sex = ""M"" "
- strSQLString = strSQLString + " AND converted_Eth_Orig = " '" + ethnicity + "' "
- If CInt(awardLevel) > 0 Then
- strSQLString = strSQLString + " AND award_level = " '" + awardLeve + "' "
- End If
- Set rs = db.OpenRecordset(strSQLString)
- iMaleCount = rs.Fields(0)
- rs.Close
- strSQLString = "SELECT COUNT(*) FROM [Step 9: Completers By Level] WHERE sex IS NULL "
- strSQLString = strSQLString + " AND converted_Eth_Orig = " '" + ethnicity + "' "
- If CInt(awardLevel) > 0 Then
- strSQLString = strSQLString + " AND award_level = " '" + awardLeve + "' "
- End If
- Set rs = db.OpenRecordset(strSQLString)
- rs.MoveFirst
- iUnknownCount = rs.Fields(0)
- rs.Close
- iTotalCount = iFemaleCount + iMaleCount + iUnknownCount
- dPercentFemale = iFemaleCount / iTotalCount
- iNewFemaleCount = iUnknownCount * dPercentFemale
- iNewFemaleCount = CInt(iNewFemaleCount * 10) / 10
- iNewMaleCount = iUnknownCount - iNewFemaleCount
- db.Close
- genderCount.additionalFemales = iNewFemaleCount
- genderCount.additionalMales = iNewMaleCount
- End Function
Expand|Select|Wrap|Line Numbers
- SELECT Title, AYR, sex, ipeds_title,
- SWITCH
- (
- sex = "M", COUNT(dw_key) + [GenderCount(converted_eth_orig)].additionalMale,
- sex = "F", COUNT(dw_key) + [GenderCount(converted_eth_orig)].additionalFemale
- ) AS TotalCount
- 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
- GROUP BY Title, ayr, ipeds_title, sex
- ORDER BY Title, ayr, ipeds_title, sex;
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