I am writing a code which extracts data from a msaccess database to create certain report. For this purpose I wrote couple of queries and tried them in msaccess. One of the query has multiple occurance of 'avg()' function in it. This query runs fine in msaccess but gives error in vb6. I am using a cursor to fetch the data.
Following is my code :
Code:Public Function get_avg_in_table(ByRef dbcon As ADODB.Connection, ByVal eventid As Integer, ByVal scriptid As Integer) As Integer Dim recordset_avg As ADODB.Recordset Dim create_cmd As ADODB.Command Dim iLoop As Integer Set create_cmd = New ADODB.Command Set recordset_avg = New ADODB.Recordset recordset_avg.Source = "SELECT Breakdown_meter.[Event ID],Avg(Breakdown_meter.Value),Avg(Breakdown_meter.Connection) FROM Breakdown_meter WHERE Breakdown_meter.[Script ID]=26 group by Breakdown_meter.[Event ID]" With recordset_avg .CursorLocation = adOpenStatic .CursorType = adOpenDynamic .LockType = adLockOptimistic Set .ActiveConnection = dbcon End With 'This is where i get error "unable to open the cursor error" recordset_avg.Open MsgBox recordset_avg.RecordCount For iLoop = 0 To (recordset_avg.RecordCount - 1) Debug.Print recordset_avg.Fields(0).Value & " " & recordset_avg.Fields(1).Value recordset_avg.MoveNext Next recordset_avg.Close End Function
I want to average around 8 columns.
can anyone please help?




Reply With Quote