Logo 
Search:

MS Office Forum

Ask Question   UnAnswered
Home » Forum » MS Office       RSS Feeds

UserForm questions - group re-naming copied objects on new multipage

  Asked By: Imelda    Date: Nov 25    Category: MS Office    Views: 1030
  

I have questions re-userforms & textboxes.

I am developing a user friendly form with shows a student progress
towards 4 National Certificates. I have developed a form with
multipages (1 for each Cert). I have placed approx 28 txtboxes & 15
labels on the 1st page for the 1st Cert. I want copy these objects
(which will be of similar name as I have named the textboxes according
to the intersection of Header Cols & Hdr Rows) in the other 3 pages
for the other 3 Certs.

Now my question is - can I some how group rename the copied objects in
the same way without having to type or paste the names for the new
objects i.e txtTtlCrs1 to txtTtlCrs2 (notice the change at the end
from 1 to 2). This (mostly) will be same for 3 & 4 etc.

Share: 

 

1 Answer Found

 
Answer #1    Answered By: Abasi Massri     Answered On: Nov 25

I tried setting up a routine to change  the names  only to discover you
can't change controls' names at runtime - but you can if you've added
the control at runtime.

So there's a work around you might like, as any label/textbox changes
you make on the first page  of the multipage  will be reflected in the
other pages automatically.

I set up a userform  (Userform1) with a multipage (MultiPage1) and set
up a few text boxes and labels on the first page (Page(0)), added a
further two pages to it to make 4 pages in total, and left the last
three pages empty.

The following code runs through each of the controls on the first page
and adds similar ones to the other three pages, same position and
size, but names them by stripping off the last character of the name
of the corresponding control on the first page and adding the single
digit of the page number it's on.

Sub blah()
For Each mctrl In UserForm1.MultiPage1.Pages(0).Controls
For i = 1 To 3
Set newCtrl = UserForm1.MultiPage1.Pages(i). _
Controls.Add("Forms." & TypeName(mctrl) & ".1")
With newCtrl
.Name = Left(mctrl.Name, Len(mctrl.Name) - 1) & i + 1
'remove the next two If statements, they're just to
'show the names of the controls on the form  itself, to debug.
If TypeName(newCtrl) = "Label" Then .Caption = .Name
If TypeName(newCtrl) = "TextBox" Then .Value = .Name
.Left = mctrl.Left
.Height = mctrl.Height
.Top = mctrl.Top
.Width = mctrl.Width
End With
Next i
Next mctrl
UserForm1.Show
End Sub

(This was in a standard module, but you could place it in the
Initialize event for the form itself with a little adjustment.)

There may be other controls on each page; if you need to filter out
only those you need renaming, come back to me.

 




Tagged: