If this is your first visit, be sure to
check out the FAQ by clicking the
link above. You may have to register
before you can post: click the register link above to proceed. To start viewing messages,
select the forum that you want to visit from the selection below.

Unanswered: Move command button onto tab without losing onclick event

Hello, Access 2002, am rejigging a form, have insert some blank tabbed sections and want to now move exisiting command buttons onto the various tabs.
Various attempts have resulted in command buttons on the tabs but they lose their Onclick event procedures.
Is there any way to move or copy a control on to a tab with losing its event procedure ?

Have searched the forum and the web and I kind of think the answer is no

If the controls in question were simply moved from the form's Detail Section directly to a page of the Tabbed Control, you need to "reconnect" the controls and their event codes.

Courtesy of ADezii at Bytes.com, this code will "reconnect" controls to some selected Events (OnClick and AfterUpdate in this example.) It can be modified for other Events, and has the advantage of updating a large number of controls without doing them one by one.

Code:

Private Sub Form_Load()
Dim ctl As Control
For Each ctl In Me.Controls
If (TypeOf ctl Is TextBox) Or (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

Alternatively, in Design View, you can select a control, go into Properties Events and click on the event in question, to take you to the code window, as if you were setting it up for the first time. Once in the code window, simply return to Design View. The control is now "connected" to its code and the hotkey will work. The disadvantage to this is that it's time consuming if it involves a lot of controls.

Hope this helps!

The problem with making anything foolproof...is that fools are so darn ingenious!

ADezii's code is tried and true, so there shouldn't be any problems. As I said, it can be modified to include other Events and/or other types of Controls.

The disconnection of Events from Controls when moving them to Tabbed Pages is really kind of odd, since Controls on the Pages are treated, in every other way, as if they were directly on the Detail Section of the Form.

Good luck with your project!

Linq ;0)>

Hope this helps!

The problem with making anything foolproof...is that fools are so darn ingenious!