Hi again Ken,
I have another kicker simular to the last. I have the following code:
strdata = Choose([Forms]![Add Special Heading]![SpecialIndex1], _
[Special0], [Special1], [Special2], [Special3], [Special4],
[Special5], _
[Special6], [Special7], [Street], [City State Zip], [Phone],
[Teacher], _
[Grade])
I want to place this code in another for next loop where "SpecialIndex1",
"SpecialIndex2", .... are text boxes on the form (Add Special Heading) that
calls the report. I tried using the "Controls" and "Me.Controls" in every
combination that I could think of. Is the a way to do what I need? If I can
resolve this and with my previous changes, I'll reduce my total code by about
90 percent.
Thanks again,
Phil
Ken Snell said:
Sorry for my misunderstanding. As I reread your post, I see that you did
state the first character of the data. My mistake! Glad you were able to
make it work!
--
Ken Snell
<MS ACCESS MVP>
Hi Ken,
Sorry, I guess I didn't make myself clear. If the data in the text box
started with the "_" character I wanted to set the visible to false. The
text box names did not start with the "_" character. Thanks again, with
your
help I did figure out what I needed.
Phil
:
What you propose will not work with the code snippet that I gave you. It
is
written to do the "operations" only on controls that being with the word
"head" and have a number after that word. Thus, none of those controls
will
have a _ character as the first character.
If what you want is to have the loop handle both types of textbox names,
then you'll need something more like what I posted the second time:
Dim ctl As Control
For Each ctl In Me.Controls
If ctl.ControlType = acTextBox Then
If Left(ctl.Name, 1) = "_" Then ctl.Visible = False
If Left(ctl.Name, 4) = "head" Then
With ctl
.Width = MyValue
.Left = MyValue
End With
End If
End If
Next ctl
--
Ken Snell
<MS ACCESS MVP>
Hi Ken,
Actually I'm still working on the same thing. Here is the basic code
that
you gave me before with the line that I need to use the Left function
in.
If
the first character of the data is a "_" I want the .Visible atribute
to
be
False for that text box.
Dim lngI As Long
For lngI = 1 To 5
With Me.Controls("head" & lngI)
.Width = MyValue
.Left = MyValue
' this next line is where I need help.
if (Left(textbox & lngI), 1) = "_") then .Visible = False
End With
Next lngI
I'm doing a lot more that this code shows. I have 14 boxes that I'm
formatting and showing or not showing. I did have 14 sets of code and
I'm
trying to do it all within a loop using your above code.
Thanks for your help.
Phil
:
You had stated that the textbox always starts with "head"... so I am
assuming that you're now talking about a completely different setup?
Dim ctl As Control
For Each ctl In Me.Controls
If Left(ctl.Name, 1) = "_" Then
With ctl
.Width = MyValue
.Left = MyValue
End With
End If
Next lngI
--
Ken Snell
<MS ACCESS MVP>
Thanks Ken that helped. One more question - what is the syntax if
I
want
to
test the first character for a '_'? I again tried various
combinations of
the "Left" function, but can't get the code right....
For example I tried:
if (Left(textbox & intx), 1) = "_") then.........
being within the "with" loop I can't get the syntax right.
Thanks again
Phil
:
Generic code that you can modify:
Dim lngI As Long
For lngI = 1 To 5
With Me.Controls("head" & lngI)
.Width = MyValue
.Left = MyValue
End With
Next lngI
--
Ken Snell
<MS ACCESS MVP>
HI,
I have a report with 14 text boxes in the heading. I
currently
format
the
text boxes using the .left and .width arguments to set the
left
edge
and
width of each box. The boxes are named head1, head2,
head3.....
I
would
like to do the formatting in a do loop, but I can't figure out
how
to
reference the text boxes. I tried using and interger variable
"intx"
with
the following code options for the .left argument and simular
code
for
the
.width:
"head" & intx.left
["head" & intx].left
[("head" & intx)].left
Plus others.....
I always get a syntax error or a can't find field.
I know that using the len function that len("head" + intx)
will
give
me
the
length of the data, but I can't figure out how to reference
the
..left
or
.width arguments.
Any help would be appreciated.
Thanks,