10-09-2001, 06:21 AM
I would like to have basic informations on how do we handle forms that are loaded via an array. My problem remains the same. Suppose I have Form(1), Form(2) Form(3) and Form(4) loaded in memory, if I unload Form(3), I would like to see Form(4) takes its place. I know it has something to do with redimming the array VS UBound or something...I am all lost here :(
10-09-2001, 06:29 AM
Set FormArray(3) = FormArray(4)
Set FormArray(4) = Nothing</pre>
You can then ReDim the array if you wish.
10-09-2001, 06:35 AM
I think you have some misconception.
There is no arrays of Forms.
There is only Collection of Forms.
The notation FormABC(Number) is an invalid syntax.
10-09-2001, 06:44 AM
I don't think he's talking about the Forms collection. I think has a normal array of form references. I.e.: Dim ar() as Form
10-09-2001, 06:57 AM
Thanx Banjo, I'll try this :)
10-09-2001, 07:04 AM
If there is an array of form, it should be loaded into the
collection of forms to work.
When an element of the array is unloaded from the collection
of forms, it remains in the array, at its position.
In order to remove an element in the array, the array should
be resized. It is a different matter from unload a form from
the collection of forms.
10-09-2001, 07:07 AM
That's why I said that he needed to set the unused array element to Nothing.
10-09-2001, 07:07 AM
I just have to resize by removing 1 to the previous total ?
10-09-2001, 07:14 AM
I am getting an error when I am trying to Redim Preserve my Form array a second time ( the first time, no problems ).
I am calling Redim Preserve ( 1 To TotalTemplate ) and this is generating an error the second time around :(
10-09-2001, 07:20 AM
Dim arrForm() As Form
Private Sub Form_Load()
ReDim arrForm(1 To 3)
Set arrForm(1) = New FormB
Set arrForm(2) = New FormC
Set arrForm(3) = New FormD
Private Sub Form_Resize()
Dim i As Integer
For i = 1 To UBound(arrForm)
Private Sub cmdFeedBack_Click()
Dim i As Integer, msg As String
Dim frm As Form
For Each frm In Forms
msg = msg & frm.Name & vbNewLine
MsgBox msg, vbOKOnly, "Array of Forms"
Private Sub cmdResize_Click()
Set arrForm(2) = arrForm(3)
ReDim Preserve arrForm(1 To UBound(arrForm) - 1)
10-09-2001, 07:32 AM
OKay thanx, my routine works quite well now.
My only problem is when I try to Redin Preserve my routine, seems to generates an error each time the seonc time around...
10-09-2001, 07:58 AM
It normally a good idea to use LBound to UBound instead of 1 to UBound. This will be the source of bugs in the future if for some reason you change it to a zero-based array.
10-09-2001, 08:49 AM
Thanx everyone. My function is now bug free :)