Buttons and tabs... tabs and buttons. ARGH.

TomH

Registered User.
Local time
Today, 01:06
Joined
Nov 3, 2008
Messages
111
I've placed a bunch o'buttons on a series of tabs in a form, but a few should be in the main form's header area. When I move, copy and paste, cut and paste... anything... I lose my event code related to the button.

Any help in how to avoid this or a workaround would be greatly appreciated.
 
Found a Missinglinq post on another forum
http://www.dbforums.com/microsoft-a...on-onto-tab-without-losing-onclick-event.html
that contained this code, attributed to ADezii at Bytes.com.

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


Cut and paste your command buttons. Load. Done.

VERY NICE.
 
Thought I should add a caveat here, based on my observation. Though this code works perfectly, it DOES NOT put an "On Click" event on your button control. It somehow links the existing (pre-move) code to the click. So, when you look for the event code on the button's properties, the line is empty.

So, if you want that "[Event Procedure]" entry on the On Click property, you have to click on that line, click the ellipsis, click on the Code Builder entry, answer the Select question and then the code comes up. Simply close VBA and the property is updated.
 
That code relinks the procedure to the Event when the form is loaded.

ALL it does is put an [Event Procedure] into the Event but only at runtime. It won't appear in the Design view unless you switch to Design view directly from Form View and then Save the form.

Then you no longer need that OnLoad procedure because its effect has been saved.

If you simply close the VB Editor without saving the form at some point, the [Event Procedure] will be lost and you will still be using these procedures to connect to the VB at runtime.
 

Users who are viewing this thread

Back
Top Bottom