LinkBack Thread Tools Search this Thread Display Modes
Prev Previous Post   Next Post Next
  #1   Report Post  
Posted to microsoft.public.excel.programming
external usenet poster
 
Posts: 371
Default Question for Peter T - Copy Paste controls at runtime

I would appreciate further comment re your solution to copy pasting controls
and your code:

Private Sub CommandButton1_Click()
Dim newPage As Page
Dim nPages As Long
With Me.MultiPage1
nPages = .Count
Set newPage = .Pages.Add("Page" & (nPages + 1), _
"Address " & (nPages + 1), nPages)
.Pages(1).Controls.Copy
End With
newPage.Paste
End Sub

''I assume you have addressed how to add new event code to the pasted
controls. ''

I have 2 questions
1. Using the above, I find each control is pasted to the left of the
original position. They are alll drawn relative to each other just shifted
to the left. How would you correct this?
2. How do you sub-class the event code for each control collection?

I would be very grateful if you could expand a little on your previous
comments

Geoff

Code as follows:

For a cmdbutton on a page I have in the form code:
Private Sub cmdDeleteChanges_Click()
'''clear controls
ClearControls (MultiSetasides.Value)
'''set focus on first empty control
FirstControl (MultiSetasides.Value)
End Sub
Then in a standard module I have:
Sub FirstControl(k As Byte)

Dim i As Byte

'''ignore main page
If Not frmMulti.MultiSetasides.Value = 0 Then
Set ctrl = frmMulti.MultiSetasides.Pages(k).Controls
For i = 0 To 9
If (TypeOf ctrl.Item(i) Is msForms.TextBox) Then
If Trim(ctrl.Item(i).Text) = "" Then Exit For
ElseIf (TypeOf ctrl.Item(i) Is msForms.OptionButton) Then
If ctrl.Item(i).Value = False And ctrl.Item(i + 1).Value =
False Then Exit For
End If
Next i
ctrl.Item(i).SetFocus
End If
End Sub

Sub ClearControls(k As Byte)
Dim i As Byte
'''ignore main page
If Not frmMulti.MultiSetasides.Value = 0 Then
Set ctrl = frmMulti.MultiSetasides.Pages(k).Controls
For i = 1 To 9
If (TypeOf ctrl.Item(i) Is msForms.TextBox) Then
ctrl.Item(i).Text = ""
ElseIf (TypeOf ctrl.Item(i) Is msForms.OptionButton) Then
ctrl.Item(i).Value = False
End If
Next i
End If
End Sub
 
Thread Tools Search this Thread
Search this Thread:

Advanced Search
Display Modes

Posting Rules

Smilies are On
[IMG] code is On
HTML code is Off
Trackbacks are On
Pingbacks are On
Refbacks are On


Similar Threads
Thread Thread Starter Forum Replies Last Post
Add controls to Frames at Runtime Neily[_3_] Excel Programming 4 October 31st 05 02:29 PM
Does anyone have a copy of the Peter Noneley: Function list? Marc New Users to Excel 1 December 6th 04 08:52 PM
Removing Controls at RunTime? Neily[_3_] Excel Programming 1 November 25th 04 02:17 PM
How to create controls at runtime Andy Chan Excel Programming 3 August 30th 04 10:07 AM
creating controls at runtime defj Excel Programming 2 December 2nd 03 07:14 AM


All times are GMT +1. The time now is 12:30 PM.

Powered by vBulletin® Copyright ©2000 - 2025, Jelsoft Enterprises Ltd.
Copyright ©2004-2025 ExcelBanter.
The comments are property of their posters.
 

About Us

"It's about Microsoft Excel"