Thanks for your help. I did what you said and now it stops on UBound and is
asking the same thing. Here is the code:
Option Explicit
Private mcnToDatabase As Connection
Private mwksResults As Excel.Worksheet
Private Const STATE_FIPS_COL = 0
Private Const COMMODITY_COLUMN = 1
Private Const PRACTICE_COL = 2
Private Const CS = "Provider=Microsoft.Jet.OLEDB.4.0;User
ID=Admin;Mode=Share Deny None;Jet OLEDB:Engine Type=4;Data Source="
Private Const CLIENT_TAB = "CLIENT"
Private Const ALT_TAB = "ALT1"
Public Sub Run(dbPath As String)
Dim lDataRow As Long
Dim lData As Long
Dim GetAllData As Variant
Dim asData() As String
ConnectToDatabase dbPath
GetAllData = asData
'Stuff in Main that opens Excel
For lDataRow = 0 To UBound(asData(0))
Main asData(lDataRow, STATE_FIPS_COL), asData(lData, COMMODITY_COLUMN),
asData(lData, PRACTICE_COL)
'RunSolver
'Save as new workbook
Next lDataRow
End Function
"CubsFan" wrote:
> Try changing:
>
> Dim asData As String
>
> to:
>
> Dim asData() As String
>
> also, try placing it as a global above your sub 'Run'.
>
> This might help, but I don't see the code that puts the recordset data into
> the variable asData. If its a recordset that is filled in the
> 'ConnectToDatabase' routine, you might have to step through the set and get
> the data out. Also, try just assigning the data instead of 'Set" --i.e.
> GetAllData = asData
>
> hope this helps
> CF
>
> "Need Help Fast!" wrote:
>
> > What I am trying to do, is call on array and go down it and use these values
> > for another part of my macro. Everything works fine but this. Here is the
> > code.
> >
> > Option Explicit
> >
> > Private mcnToDatabase As Connection
> > Private mwksResults As Excel.Worksheet
> >
> > Private Const STATE_FIPS_COL = 0
> > Private Const COMMODITY_COLUMN = 1
> > Private Const PRACTICE_COL = 2
> >
> >
> >
> > Private Const CS = "Provider=Microsoft.Jet.OLEDB.4.0;User
> > ID=Admin;Mode=Share Deny None;Jet OLEDB:Engine Type=4;Data Source="
> >
> > Private Const CLIENT_TAB = "CLIENT"
> > Private Const ALT_TAB = "ALT1"
> >
> > Public Sub Run(dbPath As String)
> > Dim lDataRow As Long
> > Dim lData As Long
> > Dim GetAllData As Variant
> > Dim asData As String
> >
> >
> >
> >
> >
> > ConnectToDatabase dbPath
> >
> > Set GetAllData = asData()
> >
> > 'Stuff in Main that opens Excel
> >
> >
> >
> > For lDataRow = 0 To UBound(asData(0))
> > Main asData(lDataRow, STATE_FIPS_COL), asData(lData, COMMODITY_COLUMN),
> > asData(lData, PRACTICE_COL)
> >
> > 'RunSolver
> > 'Save as new workbook
> > Next lDataRow
> >
> > End Function
> >
> > It keeps giving me an error and saying "expected array". It says the array
> > isn't there, but it is. It's in the worksheet15. So if anyone can help it
> > would be greatly appreciated. Can someone tweak my code or something? Thanks
|