Re: User Define Array Data Type - Subscript out of range
- From: PatK <PatK@xxxxxxxxxxxxxxxxxxxxxxxxx>
- Date: Thu, 7 Feb 2008 09:31:02 -0800
Works just DANDY, Robert!
Thanks a ton!
PatK
"PatK" wrote:
Thanks...I am going to make these changes. I will let you know how it goes..
It may solve a problem I am having now, that I did not before, mainly, on the
.open, it is expecting a select statement (or somesuch error I have not seen
thus far), and I see you have one (altho now I am scratching my head as to
why the .open worked before, and not now).
There is not a lot of data to load into the table...about 40 entries, but I
am all for coding things efficiently, as I leverage my past work, in the
future.
Oh, and J was for a debug loop I was using later, that I exclude from the
code....LOL (sorry about that!).
Patk
Thanks again!
"Robert Morley" wrote:
The absolute fastest way to do what you want would be to use SQL statements
instead of looping code, but that would, of course, depend on what all you
need to do. So for now, I'll assume that doing all this through code will
be necessary at some point, and that your current algorithm makes sense for
what you ultimately need to do.
Given that, here are a couple of modifications I would make to your code.
My comments are out-dented; also watch out for line wrapping, but I assume
that'll be obvious:
Type dtype
strNameIn As String
IntInputOrder As Integer
strDataType As String
strNameOut As String
IntMaxLen As Integer
intOutputOrder As Integer
strDataSrcTbl As String
strDataSrcFld As String
End Type
Dim xArray() As dtype
With rs
.Open "SELECT * FROM TblStructure WHERE " & strSelect,
CurrentProject.Connection, adOpenStatic, adLockPessimistic, adCmdText
'Changing the SQL statement do do the work on the front end will
'save a lot of time compared to doing multiple .Find's.
.MoveLast
'Makes the .RecordCount accurate
'-----------------------------------------------------
'upsize the array to accomodate incoming data'
'-----------------------------------------------------
i = UBound(xArray)
'Assumes xArray is already used from a previous instance of this code.
'If not, then simply put i = -1
'Re-Dim for the entire recordset all at once...saves a LOT of time.
'This is, however, predicated on the idea that you can bump strSelect
'up to the WHERE clause, as I've done above.
ReDim Preserve xArray(.RecordCount + i)
j = 0
'What's j for?
.MoveFirst
Do Until .EOF
i = i + 1
'Moved up here to pre-increment, which is easier to manage in this instance.
'-----------------------------------------------------
' Load Array
'-----------------------------------------------------
xArray(i).strNameIn = ![FieldName-Input].Value
xArray(i).IntInputOrder = !FieldInputOrder.Value
xArray(i).strDataType = !FieldType.Value
xArray(i).strNameOut = ![FieldName-Output].Value
xArray(i).IntMaxLen = !FieldMaxLen.Value
xArray(i).intOutputOrder = !FieldOutputOrder.Value
xArray(i).strDataSrcTbl = !CalcSourceTbl.Value
xArray(i).strDataSrcFld = !CalcSourceField.Value
.MoveNext
Loop
End With
Rob
- References:
- User Define Array Data Type - Subscript out of range
- From: PatK
- Re: User Define Array Data Type - Subscript out of range
- From: Robert Morley
- Re: User Define Array Data Type - Subscript out of range
- From: PatK
- Re: User Define Array Data Type - Subscript out of range
- From: Robert Morley
- Re: User Define Array Data Type - Subscript out of range
- From: PatK
- User Define Array Data Type - Subscript out of range
- Prev by Date: Re: User Define Array Data Type - Subscript out of range
- Next by Date: Re: User Define Array Data Type - Subscript out of range
- Previous by thread: Re: User Define Array Data Type - Subscript out of range
- Next by thread: Re: User Define Array Data Type - Subscript out of range
- Index(es):
Relevant Pages
|