View Full Version : Solved: CLASS help Please
Kicker
11-12-2005, 07:59 PM
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.
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
:help
Killian
11-12-2005, 08:57 PM
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?
Kicker
11-12-2005, 09:07 PM
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
Killian
11-12-2005, 09:28 PM
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
Kicker
11-12-2005, 09:35 PM
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
Norie
11-13-2005, 07:06 AM
Kicker
Glad you've got that working.:)
But, kind of off topic, why do you have 40 command buttons on a form?
Kicker
11-13-2005, 10:07 AM
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.
Killian
11-13-2005, 10:44 AM
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 workingGlad to hear it's working :thumb
Norie
11-13-2005, 06:18 PM
Kicker
You have 49 command buttons to replicate some kind of calendar?
Why not use combo/listboxes?
Kicker
11-13-2005, 07:36 PM
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?
Norie
11-13-2005, 09:17 PM
Kicker
No need for 365 days in 1 box.
Why not have 1 combobox for month, 1 for year and 1 for day?
Kicker
11-13-2005, 10:02 PM
Because I didn't think about it. :dunno I think that is how I will do it next time though.
thanks :beerchug:
Powered by vBulletin® Version 4.2.5 Copyright © 2024 vBulletin Solutions Inc. All rights reserved.