Results 1 to 4 of 4
  1. #1
    Join Date
    Jul 2009
    Posts
    39

    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

    Thanks for any suggestions

  2. #2
    Join Date
    Jun 2005
    Location
    Richmond, Virginia USA
    Posts
    2,763
    Provided Answers: 19
    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!

    All posts/responses based on Access 2003/2007

  3. #3
    Join Date
    Jul 2009
    Posts
    39
    Many thanks for taking the time to reply, I'll try your code , looks neat !

  4. #4
    Join Date
    Jun 2005
    Location
    Richmond, Virginia USA
    Posts
    2,763
    Provided Answers: 19
    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!

    All posts/responses based on Access 2003/2007

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts
  •