Tab Control (1 Viewer)

rfear

Registered User.
Local time
Today, 20:46
Joined
Dec 15, 2004
Messages
83
I've got part way through designing a form and have now decided that it would look better if I used a tab control to display the data - it's a bit busy all on one page.

Can I retrospectively add controls to a tab ?

If I create new controls using the toolbox these automatically attach themselves to the tab page.

If I take controls that are already on the form and try to place these on a tab page, they don't seem to associate with the tab control.

If I can help it I don't want to have to rewrite all the controls I have already created.
 

missinglinq

AWF VIP
Local time
Today, 15:46
Joined
Jun 20, 2003
Messages
6,420
What you have to do, after cutting and pasting the controls onto the the tabbed page(s) you can

  1. Select the control
  2. Goto Properties
  3. Click to the right of the event to go to the code window
  4. Exit the code window
  5. Repeat for each control
The events will now be re-connected to the objects

For one or two controls this is fine, but for multiple controls it can be very time comsuming.

The following routine is based on code originally posted by a gentleman who goes by the name of ADezii on bytes.com:

It causes controls that have been moved from a standard form onto pages of a tabbed page control to be "re-connected" to their underlying code. If you should try to modify it, in order to include other type of controls/event procedures, be sure that you only try to re-connect controls to events that are appropriate! In other words, you can re-connect Command Buttons, Comboboxes and Labels to their OnClick events, but if you attempt to re-connect those same three control types to their AfterUpdate events, you will throw an error, because Labels don’t have AfterUpdate events!

This code will reset some of the more commonly used controls/events.

Code:
Private Sub Form_Load()
Dim ctl As Control

For Each ctl In Me.Controls
If (TypeOf ctl Is CommandButton) Then
If ctl.OnClick = "" Then
ctl.OnClick = "[Event Procedure]"
End If
End If
Next


For Each ctl In Me.Controls
 If (TypeOf ctl Is TextBox) Or (TypeOf ctl Is ComboBox) Then
   If ctl.AfterUpdate = "" Then
     ctl.AfterUpdate = "[Event Procedure]"
   End If
 End If
Next
End Sub

You only have to run the code one time then save your form. You can then delete the code.
 

rfear

Registered User.
Local time
Today, 20:46
Joined
Dec 15, 2004
Messages
83
Thanks. I twigged to the cut and paste method ( rather than click and drag ), the routine you describe will save me a few hours.
 

Users who are viewing this thread

Top Bottom