[AccessD] ADHB2K - frmMultiPickMSForms

John Colby jcolby at colbyconsulting.com
Thu Oct 9 07:39:55 CDT 2003


SD,

I have just finished taking this stuff (from adh 97 apparently) and turning
it into a class.  In my case I use Withevents which means that the events
for the controls are handled right inside of the class.  It appears that
this is probably how this (your) version works as well.

Withevents is a keyword used with a dim statement for controls.  The syntax
looks like:

Private WithEvents mcmdAddOne As CommandButton

The Withevent keywords can only be used in a class, which the form module is
by the way.  Withevents says essentially, "this control is dimensioned 'with
its events' being handled in this class".

Once you dimension a control in this manner, then when an event for that
control fires, control CAN be passed to code in your class.  I stress the
word CAN because it won't necessarily be done.  In order for control for a
given event to be passed to your class, the event stub has to be present in
the class AND the exact text "[Event Procedure]" has to be present in the
corresponding control event property.

Any Access developer who programs the events for forms or controls is
already familiar with these restraints, although you may not have ever
thought about them.  When you want to use some event, you usually dbl-click
in the form or control's property.  Let's take a command button as an
example.

You dbl-click in the "On Click" property of the control.
The words "[Event Procedure]" magically appear in the property.  Nothing
else has happened so far.
You click on the ellipsis off to the right of the event.
You are magically transported to the code editor and the following text is
magically inserted into the form's module (which remember is a class).

Private Sub cmdOK_MouseDown(Button As Integer, Shift As Integer, X As
Single, Y As Single)
End Sub

Remember I said that in order for control to be passed to a class you had to
have three things.

1) The control dimensioned "Withevents".
2) The exact text "[Event Procedure]" inserted in the event property of
interest in the control.
3) An event stub inserted in your class to gain control of (sink) the event
when it fires.

In essence the wizard behind the property box takes care of doing these
three things for you.

One thing to note here is that ALL controls (and the form itself) are
automatically "dimmed withevents" in a form's class module, i.e. it doesn't
have to be explicitly done.  In YOUR classes it will have to be done!

Once these three things are done, then when THAT event fires, control will
eventually be passed to your class and you can do whatever you want inside
that event stub.

So that my friend is Withevents, and that is probably why you don't see any
event handlers as you are accustomed to seeing in the form's class.  If you
don't understand this stuff, LEARN IT.  It will take your Access abilities
to a whole new level.  It's very easy to use and opens up a whole new world
of possibilities in your applications.

John W. Colby
www.colbyconsulting.com

-----Original Message-----
From: accessd-bounces at databaseadvisors.com
[mailto:accessd-bounces at databaseadvisors.com]On Behalf Of Sad Der
Sent: Thursday, October 09, 2003 2:47 AM
To: Acces User Group
Subject: [AccessD] ADHB2K - frmMultiPickMSForms


Hi group,
I've got a question regarding the form
frmMultiPickMSForms in Chapter 07 from the book
ADHK2K.

It uses listboxes and some controls to move items from
left to right, up and down, etc. I need a lot of this
functionality.

It uses a reference called: Microsoft Forms 2.0 Object
Library.

In short: I do not understand HOW it works.
First: when I open a new database I do NOT have this
reference. Why is that?

Second: How can these controls be 'controled'? It only
uses the code below. In wich MultiPikMSForms is a
class and RegisterControls and SetData are methods of
that class. How is it possible that when I click a
button action is taken? There are no events or
something like it connected to the control?!?!?!

Could somebody please explain? TIA!

SD

'------------------------------------
Private mmp As MultiPikMSForms
'------------------------------------
Private Sub Form_Load()
    ' Using MultiPikMSForms requires
    ' three steps:

    ' 1. Instantiate the object
    ' 2. Register the 8 controls with the object
    ' 3. Tell it where your data comes from

    Set mmp = New MultiPikMSForms

    mmp.RegisterControls lstAvailable, lstSelected, _
     cmdSelectOne, cmdSelectAll, cmdDeselectOne,
cmdDeselectAll, _
     cmdUp, cmdDown

    mmp.SetData "tblCustomer", "LastName"
End Sub

'------------------------------------


__________________________________
Do you Yahoo!?
The New Yahoo! Shopping - with improved product search
http://shopping.yahoo.com
_______________________________________________
AccessD mailing list
AccessD at databaseadvisors.com
http://databaseadvisors.com/mailman/listinfo/accessd
Website: http://www.databaseadvisors.com





More information about the AccessD mailing list