B
BogMonster
Hi all,
Hope someone can help. This should be obvious but I can't seem to figure it
out.
Background...
Basically, my code creates a number of forms with textbox controls on them
(MiniGrid). These effectively create textbox "grids". These "grid" forms are
then inserted into another form (MainGrid), via subform controls, to create a
major grid (I went this route because I could end up with 1200+ textboxes and
Access won't allow that many controls in a single form, so I split them up).
Finally, I have another form (InputForm) that brings the "main grid" and a
couple of other subforms together in the appropriate layout.
I then have a main form with a subform control to refer to that last
mentioned form. So the path from MainForm to a specific textbox would be
MainForm->InputForm->MainGrid->MiniGrid.TextBox
Next, I created a class GridBox that has a WithEvents textbox control that
will reference one of the grid textboxes. The idea being that user activity
in any of the grid textboxes will trigger the appropriate events that will be
sunk by the class instance's code.
I don't know if any of that is relevant to this specific problem but thought
I'd mention it anyway.
Problem...
In the MainForm's module I have a routine that cycles through all the
controls on those lowest level grid forms, creates a New GridBox and tries to
set it to reference the current control in the loop. Then it will add the new
GridBox object to a collection.
For Each ctl In .Controls (the full path is included in an earlier With
statement)
If ctl.ControlType = acTextBox Then
Set moThisTextBox = New GridBox (This works fine)
Set moThisTextBox.TextBox =ctl (This fails in
the GridBox class because ctl
references NULL)
mcolGridBoxes.Add moThisTextBox, ctl.Name (This fails because ctl
= NULL)
End If
Next ctl
What I can't understand is that when I add statements like "Debug.Print ctl.
name" inbetween the offending lines, it prints the correct name of the
control! Furthermore, if I remove the 3 lines in the loop and replace them
with lines like "ctl.BackColor = vbYellow", all the textboxes on the form are
set to yellow. So for example, the following code in the loop works just fine
ctl.BackColor = vbYellow
Debug.Print ctl.Name
Set ctl2 = ctl
ctl2.BackColor = vbRed
Obviously this changes a texbox first to Yellow, prints its name, sets a
different ctl (ctl2) to refer to ctl and then changes ctl2 to Red. All the
textboxes end up Red.
Firstly, this tells me that the path used to locate the textboxes is correct!
Secondly, this tells me that the loop does indeed loop through all the
textboxes and references them using "ctl" as I want it to.
What's really weird is that if I halt execution on the "Set ctl2 = ctl" line
of code and hover over the "ctl" variable, the QuickInfo says that ctl=NULL
and after that line "ctl2" also equals NULL. Why then does it still proceed
to change the color to Red? Surely if either variable was NULL then the color
changes and name print would fail!
I've have a fair bit of VBA experience in Excel but this is my first crack at
Access VBA. I would still expect this kind of object referencing to be the
same though.
What's going on? I've now got a headache and mild pins & needles in my left
arm! :-o
Somebody please HELP!!!!
Hope someone can help. This should be obvious but I can't seem to figure it
out.
Background...
Basically, my code creates a number of forms with textbox controls on them
(MiniGrid). These effectively create textbox "grids". These "grid" forms are
then inserted into another form (MainGrid), via subform controls, to create a
major grid (I went this route because I could end up with 1200+ textboxes and
Access won't allow that many controls in a single form, so I split them up).
Finally, I have another form (InputForm) that brings the "main grid" and a
couple of other subforms together in the appropriate layout.
I then have a main form with a subform control to refer to that last
mentioned form. So the path from MainForm to a specific textbox would be
MainForm->InputForm->MainGrid->MiniGrid.TextBox
Next, I created a class GridBox that has a WithEvents textbox control that
will reference one of the grid textboxes. The idea being that user activity
in any of the grid textboxes will trigger the appropriate events that will be
sunk by the class instance's code.
I don't know if any of that is relevant to this specific problem but thought
I'd mention it anyway.
Problem...
In the MainForm's module I have a routine that cycles through all the
controls on those lowest level grid forms, creates a New GridBox and tries to
set it to reference the current control in the loop. Then it will add the new
GridBox object to a collection.
For Each ctl In .Controls (the full path is included in an earlier With
statement)
If ctl.ControlType = acTextBox Then
Set moThisTextBox = New GridBox (This works fine)
Set moThisTextBox.TextBox =ctl (This fails in
the GridBox class because ctl
references NULL)
mcolGridBoxes.Add moThisTextBox, ctl.Name (This fails because ctl
= NULL)
End If
Next ctl
What I can't understand is that when I add statements like "Debug.Print ctl.
name" inbetween the offending lines, it prints the correct name of the
control! Furthermore, if I remove the 3 lines in the loop and replace them
with lines like "ctl.BackColor = vbYellow", all the textboxes on the form are
set to yellow. So for example, the following code in the loop works just fine
ctl.BackColor = vbYellow
Debug.Print ctl.Name
Set ctl2 = ctl
ctl2.BackColor = vbRed
Obviously this changes a texbox first to Yellow, prints its name, sets a
different ctl (ctl2) to refer to ctl and then changes ctl2 to Red. All the
textboxes end up Red.
Firstly, this tells me that the path used to locate the textboxes is correct!
Secondly, this tells me that the loop does indeed loop through all the
textboxes and references them using "ctl" as I want it to.
What's really weird is that if I halt execution on the "Set ctl2 = ctl" line
of code and hover over the "ctl" variable, the QuickInfo says that ctl=NULL
and after that line "ctl2" also equals NULL. Why then does it still proceed
to change the color to Red? Surely if either variable was NULL then the color
changes and name print would fail!
I've have a fair bit of VBA experience in Excel but this is my first crack at
Access VBA. I would still expect this kind of object referencing to be the
same though.
What's going on? I've now got a headache and mild pins & needles in my left
arm! :-o
Somebody please HELP!!!!