using do loop to format text boxes

  • Thread starter Thread starter Guest
  • Start date Start date
G

Guest

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,
 
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
 
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

Ken Snell said:
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>


Phil said:
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,
 
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>

Phil said:
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

Ken Snell said:
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>


Phil said:
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,
 
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

Ken Snell said:
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>

Phil said:
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

Ken Snell said:
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,
 
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>

Phil said:
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

Ken Snell said:
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>

Phil said:
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,
 
Try this:

Dim lngI As Long
Dim strCtrl as String
For lngI = 1 To 5
strCtrl = "Head" & lngI
With Me.Controls(strCtrl)
.Width = MyValue
.Left = MyValue
' this next line is where I need help.
if Left(.Value), 1) = "_" then
.Visible = False
End If
End With
Next lngI


--
Duane Hookom
MS Access MVP
--

Phil said:
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

Ken Snell said:
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>

Phil said:
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,
 
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

Ken Snell said:
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>

Phil said:
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

Ken Snell said:
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,
 
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>

Phil said:
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

Ken Snell said:
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>

Phil said:
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,
 
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>

Phil said:
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

Ken Snell said:
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,
 
It's not clear to me where you want to use the logic. Is it to replace the
listing of Special0, Special1, etc.? Or to use as the first argument in the
Choose function, replacing SpecialIndex1?

--

Ken Snell
<MS ACCESS MVP>




Phil said:
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>

Phil said:
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,
 
I want strdata to contain the data in Special1 or Sprecia2 or Sprcial3 ....
Grade, using SpecialIndexX as the index in the Choose function. This code is
in a "For intx = 1 to 14"/next loop where on the first pass I use the data in
textbox SpecialIndex1 which is on the FORM (Add Special Heading) that brings
up the report. On the second pass SpecialIndex2, etc. The kicker is that
the SpecialIndex1,2,3... are on the form that calls the report using a report
command button.

What I need is for the index part of the "Choose" function to look something
like:

[Forms]![Add Special Heading]![Me.Controls("SpecialIndex" & intx)]

Which dosen't work I'm sure because the controls (textboxes SpecialIndex1,
2, 3...) are on the calling form and not part of the current report.

Thanks again,
Phil

Ken Snell said:
It's not clear to me where you want to use the logic. Is it to replace the
listing of Special0, Special1, etc.? Or to use as the first argument in the
Choose function, replacing SpecialIndex1?

--

Ken Snell
<MS ACCESS MVP>




Phil said:
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,
 
The controls are on the form? OK - this is the syntax that you want to use:

[Forms]![Add Special Heading].Form.Controls("SpecialIndex" & intx).Value

--

Ken Snell
<MS ACCESS MVP>


Phil said:
I want strdata to contain the data in Special1 or Sprecia2 or Sprcial3 .....
Grade, using SpecialIndexX as the index in the Choose function. This code is
in a "For intx = 1 to 14"/next loop where on the first pass I use the data in
textbox SpecialIndex1 which is on the FORM (Add Special Heading) that brings
up the report. On the second pass SpecialIndex2, etc. The kicker is that
the SpecialIndex1,2,3... are on the form that calls the report using a report
command button.

What I need is for the index part of the "Choose" function to look something
like:

[Forms]![Add Special Heading]![Me.Controls("SpecialIndex" & intx)]

Which dosen't work I'm sure because the controls (textboxes SpecialIndex1,
2, 3...) are on the calling form and not part of the current report.

Thanks again,
Phil

Ken Snell said:
It's not clear to me where you want to use the logic. Is it to replace the
listing of Special0, Special1, etc.? Or to use as the first argument in the
Choose function, replacing SpecialIndex1?

--

Ken Snell
<MS ACCESS MVP>




Phil said:
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

:

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,
 
Back
Top