I am trying to set up an array so that I can find the max value in a table. The table is set up with field state, then months. I can read the first two months, (Jan, Feb), but when I try to read the rest I get an error in reading the rest.
I want to dynamically plot the monthly sales by state. I can do that once I find the max value. The min will be zero.
Thanks for your help.
Code as follows.
Public Function maxvalue() As Single
Dim rst As ADODB.Recordset
Dim vardata As Variant
Dim intCtr As Integer, intI As Integer
Dim intLargest As Integer
Set rst = New ADODB.Recordset
Set rst.ActiveConnection = CurrentProject.Connection
rst.CursorType = adOpenForwardOnly
rst.LockType = adLockReadOnly
rst.Open "MonthlySales"
vardata = rst.GetRows( _
Fields:=Array("Jan", "Feb", "Mar", "Apr", "May", "Jun", "Jul", "Aug", "Sep", "Oct", "Nov", "Dec"))
rst.Close
Set rst = Nothing
'Number of Rows
intCtr = UBound(vardata, 11) + 1 (this is where the problem arises, if I set the second value to greater then 2)
'Loop through all the rows, printing out the data
For intI = intCtr - 1 To 0 Step -1
Debug.Print vardata(0, intI), , vardata(1, intI)
Next intI
End Function
Thanks for your help in advance.
I want to dynamically plot the monthly sales by state. I can do that once I find the max value. The min will be zero.
Thanks for your help.
Code as follows.
Public Function maxvalue() As Single
Dim rst As ADODB.Recordset
Dim vardata As Variant
Dim intCtr As Integer, intI As Integer
Dim intLargest As Integer
Set rst = New ADODB.Recordset
Set rst.ActiveConnection = CurrentProject.Connection
rst.CursorType = adOpenForwardOnly
rst.LockType = adLockReadOnly
rst.Open "MonthlySales"
vardata = rst.GetRows( _
Fields:=Array("Jan", "Feb", "Mar", "Apr", "May", "Jun", "Jul", "Aug", "Sep", "Oct", "Nov", "Dec"))
rst.Close
Set rst = Nothing
'Number of Rows
intCtr = UBound(vardata, 11) + 1 (this is where the problem arises, if I set the second value to greater then 2)
'Loop through all the rows, printing out the data
For intI = intCtr - 1 To 0 Step -1
Debug.Print vardata(0, intI), , vardata(1, intI)
Next intI
End Function
Thanks for your help in advance.