MS Access Forum / Reports / Printing / November 2004
using do loop to format text boxes
|
|
Thread rating:  |
Phil - 27 Nov 2004 19:01 GMT 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,
 Signature Phil
Ken Snell [MVP] - 27 Nov 2004 20:00 GMT 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
 Signature Ken Snell <MS ACCESS MVP>
> HI, > [quoted text clipped - 18 lines] > Any help would be appreciated. > Thanks, Phil - 27 Nov 2004 23:33 GMT 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: > [quoted text clipped - 29 lines] > > Any help would be appreciated. > > Thanks, Ken Snell [MVP] - 28 Nov 2004 00:54 GMT 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
 Signature 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 [quoted text clipped - 42 lines] > > > Any help would be appreciated. > > > Thanks, Phil - 28 Nov 2004 17:09 GMT 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? [quoted text clipped - 63 lines] > > > > Any help would be appreciated. > > > > Thanks, Ken Snell [MVP] - 28 Nov 2004 18:38 GMT 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
 Signature Ken Snell <MS ACCESS MVP>
> Hi Ken, > Actually I'm still working on the same thing. Here is the basic code that [quoted text clipped - 86 lines] > > > > > Any help would be appreciated. > > > > > Thanks, Phil - 29 Nov 2004 02:15 GMT 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 [quoted text clipped - 119 lines] > > > > > > Any help would be appreciated. > > > > > > Thanks, Ken Snell [MVP] - 29 Nov 2004 02:43 GMT 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!
 Signature Ken Snell <MS ACCESS MVP>
> Hi Ken, > [quoted text clipped - 128 lines] > > > > > > > Any help would be appreciated. > > > > > > > Thanks, Phil - 29 Nov 2004 16:59 GMT 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 [quoted text clipped - 147 lines] > > > > > > > > Any help would be appreciated. > > > > > > > > Thanks, Ken Snell [MVP] - 29 Nov 2004 17:57 GMT 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?
 Signature Ken Snell <MS ACCESS MVP>
> Hi again Ken, > [quoted text clipped - 168 lines] > > > > > > > > > Any help would be appreciated. > > > > > > > > > Thanks, Phil - 29 Nov 2004 19:03 GMT 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
> 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 [quoted text clipped - 195 lines] > > > > > > > > > > Any help would be appreciated. > > > > > > > > > > Thanks, Ken Snell [MVP] - 30 Nov 2004 03:59 GMT 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
 Signature Ken Snell <MS ACCESS MVP>
> 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 [quoted text clipped - 164 lines] > > > > > > > > > > End With > > > > > > > > > > Next lngI news:E89792F2-F82B-4A51-AFBC-FBDF918B2499@microsoft.com...
> > > > > > > > > > > HI, > > > > > > > > > > > [quoted text clipped - 45 lines] > > > > > > > > > > > Any help would be appreciated. > > > > > > > > > > > Thanks, Duane Hookom - 28 Nov 2004 18:40 GMT 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
 Signature Duane Hookom MS Access MVP --
> Hi Ken, > Actually I'm still working on the same thing. Here is the basic code that [quoted text clipped - 97 lines] >> > > > Any help would be appreciated. >> > > > Thanks,
|
|
|