Hi all,
I ran this code last year with no problems. This year I have used the code again in exactly the same state and it does not run.
my error msg is "1004 - Unable to get the Percentile property of the WorkSheetFunction Class" I have highlighed the code in red where this occurs.
I assume this is about the linking with Excel.
I have in my references the following ticked -
VBA
Access library 9.0
OLE Automation
MS DAO 3.6
MS Excel 9.0 library
MS ADO (multi dimensional) 2.7
Any ideas on how to fix this?
many thanks
John
**********************
Private Sub cmdUpdate_03_05_Click()
Dim dbs As DAO.Database
Dim rstPercentile As DAO.Recordset
Dim rstOctscore As DAO.Recordset
Dim rstJunescore As DAO.Recordset
Dim SQL As String
Dim arrayJunescore
'**************************
'IL
Set dbs = CurrentDb
SQL = "DELETE * FROM [03_05_CountyLine_IL_Percentile]"
dbs.Execute SQL
Set rstPercentile = dbs.OpenRecordset("03_05_CountyLine_IL_Percentile", dbOpenDynaset)
SQL = "SELECT Distinct [October_2003_IL_Average_Points_Score] FROM [03_05_CountyLine_IL_Percentile_query]"
Set rstOctscore = dbs.OpenRecordset(SQL, dbOpenForwardOnly)
Do While Not rstOctscore.EOF
SQL = "SELECT June_2005_IL_Average_Points_Score" & _
" FROM 03_05_CountyLine_IL_Percentile_query" & _
" WHERE October_2003_IL_Average_Points_Score = Cint('" & rstOctscore![October_2003_IL_Average_Points_Score] & "')"
Set rstJunescore = dbs.OpenRecordset(SQL)
rstJunescore.MoveLast
rstJunescore.MoveFirst
' Pass scores from recordset to array.
arrayJunescore = rstJunescore.GetRows(rstJunescore.RecordCount)
rstJunescore.Close
With rstPercentile
.AddNew
![October_2003_IL_Average_Points_Score] = rstOctscore![October_2003_IL_Average_Points_Score]
'--- Pass array to Excel Percentile function.
![25%_VA_Lower] = xl.WorksheetFunction.Percentile(arrayJunescore, 0.25)
![50%_VA_Median] = xl.WorksheetFunction.Percentile(arrayJunescore, 0.5)
![75%_VA_Upper] = xl.WorksheetFunction.Percentile(arrayJunescore, 0.75)
.Update
End With
rstOctscore.MoveNext
Loop
Set rstPercentile = Nothing
Set rstOctscore = Nothing
Set rstOctscore = Nothing
Set dbs = Nothing
MsgBox "Updated table with 25% ,50%, 75% Percentiles for IL."
End Sub
I ran this code last year with no problems. This year I have used the code again in exactly the same state and it does not run.
my error msg is "1004 - Unable to get the Percentile property of the WorkSheetFunction Class" I have highlighed the code in red where this occurs.
I assume this is about the linking with Excel.
I have in my references the following ticked -
VBA
Access library 9.0
OLE Automation
MS DAO 3.6
MS Excel 9.0 library
MS ADO (multi dimensional) 2.7
Any ideas on how to fix this?
many thanks
John
**********************
Private Sub cmdUpdate_03_05_Click()
Dim dbs As DAO.Database
Dim rstPercentile As DAO.Recordset
Dim rstOctscore As DAO.Recordset
Dim rstJunescore As DAO.Recordset
Dim SQL As String
Dim arrayJunescore
'**************************
'IL
Set dbs = CurrentDb
SQL = "DELETE * FROM [03_05_CountyLine_IL_Percentile]"
dbs.Execute SQL
Set rstPercentile = dbs.OpenRecordset("03_05_CountyLine_IL_Percentile", dbOpenDynaset)
SQL = "SELECT Distinct [October_2003_IL_Average_Points_Score] FROM [03_05_CountyLine_IL_Percentile_query]"
Set rstOctscore = dbs.OpenRecordset(SQL, dbOpenForwardOnly)
Do While Not rstOctscore.EOF
SQL = "SELECT June_2005_IL_Average_Points_Score" & _
" FROM 03_05_CountyLine_IL_Percentile_query" & _
" WHERE October_2003_IL_Average_Points_Score = Cint('" & rstOctscore![October_2003_IL_Average_Points_Score] & "')"
Set rstJunescore = dbs.OpenRecordset(SQL)
rstJunescore.MoveLast
rstJunescore.MoveFirst
' Pass scores from recordset to array.
arrayJunescore = rstJunescore.GetRows(rstJunescore.RecordCount)
rstJunescore.Close
With rstPercentile
.AddNew
![October_2003_IL_Average_Points_Score] = rstOctscore![October_2003_IL_Average_Points_Score]
'--- Pass array to Excel Percentile function.
![25%_VA_Lower] = xl.WorksheetFunction.Percentile(arrayJunescore, 0.25)
![50%_VA_Median] = xl.WorksheetFunction.Percentile(arrayJunescore, 0.5)
![75%_VA_Upper] = xl.WorksheetFunction.Percentile(arrayJunescore, 0.75)
.Update
End With
rstOctscore.MoveNext
Loop
Set rstPercentile = Nothing
Set rstOctscore = Nothing
Set rstOctscore = Nothing
Set dbs = Nothing
MsgBox "Updated table with 25% ,50%, 75% Percentiles for IL."
End Sub