Tek-Tips is the largest IT community on the Internet today!

Members share and learn making Tek-Tips Forums the best source of peer-reviewed technical information on the Internet!

  • Congratulations Chriss Miller on being selected by the Tek-Tips community for having the most helpful posts in the forums last week. Way to Go!

Design / Layout form controls via code 1

Status
Not open for further replies.

RSfromCO

Programmer
May 3, 2002
149
US
I have a form with a bunch of rows and columns of checkboxes. I would like to name and position the checkboxes with a set of code rather than setting the properties of each checkbox using the form editor.

Can someone give me an example of how to properly open the form in design mode and execute a set of code that will step through the controls and rename them and reposition them (while the form is in design mode).

I have a routine which steps through the controls of the form and I can read each control name, left and top values. It won't let me modify any of those values however without the form being in "design mode" and I can't run the routine when I open it up in design mode. Hmmmm.
 
Try doing this from another form and use a reference like this one:

Code:
[COLOR=blue]Dim[/color] MyClosedfrm [COLOR=blue]As[/color] Form, ctrl [COLOR=blue]As[/color] Control

[COLOR=blue]Set[/color] MyClosedfrm = Forms![!]NameOfYourFormHere[/!]

[COLOR=blue]For Each[/color] ctrl [COLOR=blue]In[/color] MyClosedfrm.Controls
     [COLOR=green]'Your code here[/color]
[COLOR=blue]Next[/color] ctrl

Born once die twice; born twice die once.
 
What I posted will generate an error [blush]! I'm not sure what the proper syntax is, but I know you can refer to items in a collection this way. Properties on an open form like Top and Left are read only, that's why I suggested trying from a closed perspective. See if you can get it to work.

Tom

Born once die twice; born twice die once.
 
ThomasLafferty said:
[blue]What I posted will generate an error ! I'm not sure what the proper syntax is, but . . .[/blue]
Thats because you [red]forgot to open the form![/red]
Code:
[blue]   Dim MyClosedfrm As Form, ctrl As Control

   docmd.OpenForm "[red][b]NameOfYourFormHere[/b][/red]",acDesign
   Set MyClosedfrm = Forms![red][b]NameOfYourFormHere[/b][/red]

   For Each ctrl In MyClosedfrm.Controls
        'Your code here
   Next ctrl[/blue]

Calvin.gif
See Ya! . . . . . .
 
Thanks for the reminder...
Ya know AceMan, it's been a loooooong day. How the heck are ya anyhow?

Tom

Born once die twice; born twice die once.
 
AceMan is always good Tom!

I just gotta fix everything else! . . . the car, the kids, my life . . . ;-)

Calvin.gif
See Ya! . . . . . .
 
Tom . . .

BTW: the [blue]left & top[/blue] properties are [blue]read/write![/blue] The only problem is if you intend to position the control with a Top property greater than the section the control resides in, [blue]you have too resize the section first![/blue]

Example: if you wish to set the Top property of a control in the Detail Section to 1" and the detail height is set to .5", the detail height has to be set to 1" or greater first! . . .

Calvin.gif
See Ya! . . . . . .
 
How are ya RSfromCO . . .
RSfromCO said:
[blue]I can read each control name, left and top values. [purple]It won't let me modify any of those values however without the form being in "design mode"[/purple] . . .[/blue]
When assigning Left,Top,Width,Height VBA uses a unit of measure called [blue]Twips![/blue]

1Twip = 1/1440 of an inch . . . so that

Twips = 1440 * Inches
Code:
[blue]   Me!ControlName.Top = 1440 * 1[/blue]
This puts the control at the 1inch mark in the section it resides in.
TheAceMan said:
[blue]Be aware:If you attempt to position the control outside the current values of Width & Height for the section and error will occur![/blue]
To get around this you have to resize the section first!

The only reason to make these adjustments in [blue]design view[/blue] is so you can save them as the new defaults. Other than that you shouldn't have any problems . . .

[blue]Your Thoughts? . . .[/blue]

Calvin.gif
See Ya! . . . . . .
 
Status
Not open for further replies.

Part and Inventory Search

Sponsor

Back
Top