G
Geoff
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
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