
Originally Posted by
jemidiah
Thanks for the suggestions, wish there was a way but apparently there isn't.
No one said it's not possible, we just said that it is not recommended... and that there are better ways to do it.
This is an example of how it's done for your original question:
VB Code:
Option Explicit
Private Type tStruct
Str As String
DT As Date
End Type
Private ArrType() As tStruct
Private Sub Form_Load()
Dim InsertType As tStruct
Dim K As Long
ReDim ArrType(1)
ArrType(0).DT = #4/1/2005#
ArrType(0).Str = "Hello world..."
ArrType(1).DT = #5/1/2005#
ArrType(1).Str = "blah blah 1"
InsertType.DT = #6/1/2005#
InsertType.Str = "blah blah 2"
InsertStructure ArrType, InsertType, 1
For K = 0 To UBound(ArrType)
Debug.Print K, ArrType(K).DT, ArrType(K).Str
Next K
End Sub
Private Sub InsertStructure(Arr() As tStruct, Insert As tStruct, Index As Long)
Dim K As Long
ReDim Preserve Arr(UBound(Arr) + 1)
For K = UBound(Arr) To Index + 1 Step -1
Arr(K) = Arr(K - 1)
Next K
Arr(Index) = Insert
End Sub
It works by re-sizing the array and then "shifting" all data up after the index you want to insert.
This works fine for small arrays, but if you have a lot of data, you will see that it is a significant decrease in processing using this method.
The way I said first, using a collection of classes it is much faster when you have many records.