If this is your first visit, be sure to check out the FAQ by clicking the link above. You may have to register before you can post: click the register link above to proceed. To start viewing messages, select the forum that you want to visit from the selection below. |
|
|
|
Thread Tools | Display Modes |
#1
|
|||
|
|||
using do loop to format text boxes
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, -- Phil |
#2
|
|||
|
|||
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" wrote in message ... 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, -- Phil |
#3
|
|||
|
|||
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 [MVP]" wrote: 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" wrote in message ... 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, -- Phil |
#4
|
|||
|
|||
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" wrote in message ... 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 [MVP]" wrote: 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" wrote in message ... 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, -- Phil |
#5
|
|||
|
|||
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 [MVP]" wrote: 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" wrote in message ... 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 [MVP]" wrote: 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" wrote in message ... 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, -- Phil |
#6
|
|||
|
|||
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" wrote in message ... 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 [MVP]" wrote: 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" wrote in message ... 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 [MVP]" wrote: 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" wrote in message ... 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, -- Phil |
#7
|
|||
|
|||
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" wrote in message ... 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 [MVP]" wrote: 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" wrote in message ... 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 [MVP]" wrote: 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" wrote in message ... 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, -- Phil |
#8
|
|||
|
|||
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 [MVP]" wrote: 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" wrote in message ... 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 [MVP]" wrote: 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" wrote in message ... 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 [MVP]" wrote: 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" wrote in message ... 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, -- Phil |
#9
|
|||
|
|||
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" wrote in message ... 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 [MVP]" wrote: 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" wrote in message ... 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 [MVP]" wrote: 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" wrote in message ... 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 [MVP]" wrote: 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" wrote in message ... 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, -- Phil |
#10
|
|||
|
|||
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 [MVP]" wrote: 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" wrote in message ... 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 [MVP]" wrote: 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" wrote in message ... 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 [MVP]" wrote: 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" wrote in message ... 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 [MVP]" wrote: 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" wrote in message ... 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, -- Phil |
|
Thread Tools | |
Display Modes | |
|
|
Similar Threads | ||||
Thread | Thread Starter | Forum | Replies | Last Post |
Text Boxes | J. Toews | Setting Up & Running Reports | 14 | August 3rd, 2005 06:24 PM |
How does the "auto" setting work in Paragraph Spacing? | Joey | General Discussion | 9 | October 11th, 2004 08:44 PM |
Reply to HTML email using Plain Text format | Tom Ostrand | General Discussion | 1 | June 23rd, 2004 10:18 PM |
More alternatives to text boxes. | David Young | Page Layout | 2 | April 26th, 2004 04:47 PM |
Format the content of a cell as Text | CLR | Worksheet Functions | 1 | September 30th, 2003 01:19 PM |