Controls in a form

D

DMc2005

Hi

I currently have a userform that has about 4dozen mixed controls in it in a
page Control.

At present i have to reference every control like txtName1.value.

the controls have not been put onto the form in the way that i want to
access them.

Is there an easy way to access them, like using a number and if yes can i
change the orders of the numbers to the order i want to access the controls.

My file is 1.5mb in size, any ideas why.

David
 
A

Anne P.

David,

To answer your second question first: if I am understanding correctly what
you are asking, if the controls were placed on the form in a haphazard
manner, you can set the order in which a user tabs through the controls on
the userform. To do this, select the userform and choose View, Tab Order.
From this dialog box, you can set the order of how the user tabs through the
controls. Several notes on this procedure: First, if you have a text box
(or combo box or listbox) for User Name and a Label for Username, place the
label above the other control in the tabbing order. Second, if you have any
frames on the user form, the controls inside the frame will not appear in
the list. First, set the frame in the correct order with the other controls
and exit out of View, Tab Order. Then, select each frame individually and
choose View, Tab Order to set the order of controls inside the frame.

To answer the first question: you don't mention what you are doing with the
values on the userform. I am assuming that you are inserting them into a
finished document. If so, for any control that has a text (or caption
value), name the bookmark in the document with the same name as the control
on the userform. For example, you have a textbox named txtUserName, in the
document where this value should be placed create a bookmark named
"txtUserName"; for an option button named optNewYork, create a bookmark
named "optNewYork" in the document. Then, in the commandbutton click event
(usually an OK or Finish button), place the following code:

Dim ctrl As Control

'Loop thru controls and find ones that match bookmark name and then fill
bookmark

'with contents of control

For Each ctrl In Me.Controls

If ActiveDocument.Bookmarks.Exists(ctrl.Name) Then

ActiveDocument.Bookmarks(ctrl.Name).Range.Text = ctrl.Text

End If

Next



This line of code will fill all bookmarks in the document whose name matches
the control on the userform. You then only have to worry about controls
that cannot be filled this way (the only ones I have not been able to fill
this way are image controls and checkboxes.



Hope this helps.



Anne P.
 

Ask a Question

Want to reply to this thread or ask your own question?

You'll need to choose a username for the site, which only take a couple of moments. After that, you can post your question and our members will help you out.

Ask a Question

Top