Consulting

Results 1 to 12 of 12

Thread: Solved: CLASS help Please

  1. #1

    Solved: CLASS help Please

    I have a form with approx 40+ command buttons on it. I need to add them to a collection so that I can click on one and have the click method picked up and executed depending which button was clicked. I have been fighting this for several weeks and looking at the boards....Can't seem to find exactly what I need.

    [VBA]
    Option Compare Database
    Option Explicit

    Public rptDate As Date
    Public colDate As Collection

    Private Sub form_load()
    Dim n As Long
    Dim m As Long
    Dim i As Long
    Dim strDte As String
    Dim strCal As String
    Dim ctl As Control
    Dim cLEvents As clsCommandButton


    Set colDate = New Collection
    For Each ctl In Controls
    If TypeName(ctl) = "CommandButton" Then
    Set cLEvents = New clsCommandButton
    Set cLEvents.mLGroup = ctl
    colDate.Add cLEvents
    Debug.Print TypeName(ctl)
    End If
    Next
    End Sub





    'The following is the Class clsCommandButton

    Option Compare Database
    Public WithEvents mLGroup As CommandButton

    Private Sub mLGroup_Click()
    Debug.Print "this is a test"
    end sub
    [/VBA]



    ttfn

    Kicker

  2. #2
    VBAX Master Killian's Avatar
    Joined
    Nov 2004
    Location
    London
    Posts
    1,132
    Location
    Hi Kicker

    The method you're using for this is fine. So is the problem now that you want to have different actions for groups of buttons?
    K :-)

  3. #3
    No. When I click on one of the command buttons, nothing happens. It doesn't print anything to debug. If I could get this one working, I think I can get the rest.

    Pulling my hair out
    ttfn

    Kicker

  4. #4
    VBAX Master Killian's Avatar
    Joined
    Nov 2004
    Location
    London
    Posts
    1,132
    Location
    Ahh, yes, frustrating, because it should work.
    I can't test it in Access 'til Monday, so if you haven't got it sorted by then I'll post back
    K :-)

  5. #5
    I guess this is stupid is a stupid does. I kept playing with the form and some of the "extra" command buttons and discovered (by accident) that the "on click" property of the ones I wanted were blank while the others were set to [event procedure].

    go figure..got it working
    ttfn

    Kicker

  6. #6
    VBAX Master Norie's Avatar
    Joined
    Jan 2005
    Location
    Stirling, Scotland
    Posts
    1,831
    Location
    Kicker

    Glad you've got that working.

    But, kind of off topic, why do you have 40 command buttons on a form?

  7. #7
    Just because...

    No, actually, where I work doesn't allow us to "add" ocx/dll files to the network computers. A little project I am working on pulls data based on a date and created a very simple calendar due to the lack of mscal. 5 rows of 7. For being as simple as it is, it works pretty well. (now...LOL).

    I have been using the form with next/previous buttons to change the date and/or type in a new date. But, we are wanting to look further ahead to project resource loading and I would have used mscal in VB6....but, we can't do it that way.

    If you want the basic form, I would be happy to zip it and post it.
    ttfn

    Kicker

  8. #8
    VBAX Master Killian's Avatar
    Joined
    Nov 2004
    Location
    London
    Posts
    1,132
    Location
    Quote Originally Posted by Kicker
    I guess this is stupid is a stupid does. I kept playing with the form and some of the "extra" command buttons and discovered (by accident) that the "on click" property of the ones I wanted were blank while the others were set to [event procedure].

    go figure..got it working
    Glad to hear it's working
    K :-)

  9. #9
    VBAX Master Norie's Avatar
    Joined
    Jan 2005
    Location
    Stirling, Scotland
    Posts
    1,831
    Location
    Kicker

    You have 49 command buttons to replicate some kind of calendar?

    Why not use combo/listboxes?

  10. #10
    I am not sure I want to have 365 days represented by individual lines in a combo or list box. Besides, the users are comfortable using a standard looking calendar layout. Or is there an "easy" way of using list boxes?
    ttfn

    Kicker

  11. #11
    VBAX Master Norie's Avatar
    Joined
    Jan 2005
    Location
    Stirling, Scotland
    Posts
    1,831
    Location
    Kicker

    No need for 365 days in 1 box.

    Why not have 1 combobox for month, 1 for year and 1 for day?

  12. #12
    Because I didn't think about it. I think that is how I will do it next time though.

    thanks
    ttfn

    Kicker

Posting Permissions

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