[AccessD] =function() in .onclick

John W. Colby jwcolby at colbyconsulting.com
Tue Jan 13 05:32:48 CST 2004


Chris,

>do you have a lot of variants for say textboxes or do you prefer to add
parameters at runtime to sink different events / control behavior?

I actually have an entire framework that does all of this stuff.  I have a
form class that sinks all of the form's events.  That class has a collection
which holds a class instance for each control found on the form.  I then
have classes for each control type which implement standard behaviors which
I find useful - dblclick for a combo can open a list form for entering or
correcting data contained in the combo, NotInList can add data to the table
behind the combo and requery the combo when done etc.  The form class has a
scanner that cycles through all the controls in its form's control
collection, instantiating a class for each control found (that I have a
class for anyway).

IOW, as the form loads, it scans for all controls, loads a class for each
control found and saves a pointer to that control in the control class
collection in the form's header.

I then use what I call SysVars or System Variables to enable / disable
specific form / control functionality.  It turns out I have to "set up"
things like the double click and NotInList for a combo anyway, i.e. I have
to tell the combo the name of the form or the name of the table and the
field in the table to place data in NotInList.  My form open ends up looking
something like:

Option Compare Database
Option Explicit
Public WithEvents fclsFrm As dclsFrm

Private Sub Form_Open(Cancel As Integer)
On Error GoTo Err_Form_Open
    Set fclsFrm = New dclsFrm
    fclsFrm.Init Nothing, Me, Cancel
    If Cancel Then Exit Sub
    'init the combo dbl-click and NotInList
    On Error Resume Next
    With fclsFrm.Children
        .Item("cboCountry").NotInListData "", "", "lfrmCountry"
        .Item("cboState").NotInListData "", "", "lfrmState"
    End With
    'look for the lfrm used by these combos.
    'fclsFrm.Children("cboCountry").LFrm = "lfrmCountry"
    'fclsFrm.Children("cboState").LFrm = "lfrmState"
Exit_Form_Open:
Exit Sub
Err_Form_Open:
    Select Case Err
    Case 0      '.insert Errors you wish to ignore here
        Resume Next
    Case Else   '.All other errors will trap
        Beep
        MsgBox Err.Description, , "Error in Sub tfrmClients.Form_Open"
        Resume Exit_Form_Open
    End Select
    Resume 0    '.FOR TROUBLESHOOTING
End Sub

As you can see, I dim a class for the form (fclsFrm), then in OnOpen I
instantiate it.  By the time the form class init returns all the control
classes have been loaded and are sitting in the children collection keyed on
control name.  I then "set up" things like NotInList by calling a function
in the combo's class passing in the name of the form (and also table / field
for single field list tables).  Sometimes I want the NotInList to open a
form (it is complex data with many fields), sometimes I want it to just
enter the data into a specific field in the table (it is a simple list like
titles or colors).

So, the answer to your question is, I have the generic functionality I need
for the controls already in the class for that control type.  I can use it
or not depending on whether I tell the class to do so.  Very form /
application specific behaviors I will generally program out in a separate
class.

John W. Colby
www.ColbyConsulting.com

-----Original Message-----
From: accessd-bounces at databaseadvisors.com
[mailto:accessd-bounces at databaseadvisors.com]On Behalf Of
chris at thecube.net
Sent: Tuesday, January 13, 2004 6:08 AM
To: accessd at databaseadvisors.com
Subject: RE: [AccessD] =function() in .onclick


John,

Thanks for the 'warm' response <g>.

I think i will get on and write the checkbox class to handle all of the
checkboxes, on the subject
of WithEvents/DEEP, do you have a lot of variants for say textboxes or do
you prefer to add
parameters at runtime to sink different events / control behaiviour?

Cheers John

Chris
----- Original Message -----
From: John W. Colby
To:  "Access Developers discussion and problem
solving"<accessd at databaseadvisors.com>
Sent: Tue, 13 Jan 2004 05:39:56 -0500
Subject: RE: [AccessD] =function() in .onclick

I can't help you as to why it sometimes works and others it doesn't.
However I'd like to say I HATE it when developers do this (and I have to
maintain it).  I routinely use the find dialog to find instances of code.
Doing it like that means that I have to use a find and replace utility
instead which is much more intrusive to my development effort.

Another thing is that if you ever intend to use Withevents, they don't fire
unless the words [Event Procedure] are in the property.  If you have an
event stub, you can use withevents (sink the event in a class) and the event
handler in the form at the same time - the event handler in the class simply
gets control first.  Doing it with the function call in the property
prevents sinking that control's events anywhere else.

Now...

If you ever handed that application off to someone like myself (who uses
withevents), I build a class that directly pokes the words [Event Procedure]
into the control's event property (to make sure the event fires) and now MY
class works but your functionality abruptly ceases to work.

Just thought I'd throw that out there.

If I were you I'd probably write a class that handles those checkboxes,
either individually or en mass.

John W. Colby
www.ColbyConsulting.com

-----Original Message-----
From: accessd-bounces at databaseadvisors.com
[mailto:accessd-bounces at databaseadvisors.com]On Behalf Of
chris at thecube.net
Sent: Tuesday, January 13, 2004 5:24 AM
To: accessd at databaseadvisors.com
Subject: [AccessD] =function() in .onclick


Hi All,

Instead of writing 54 event procedures, i simply iterate through a
collection of checkboxes and set
their AfterUpdate property to a function like so:

for index = 1 to 54
me("chkTemplate" & index).Afterupdate = "=toggleTemplate(" & index & ")"
next

now, on some Access 2000 installs this works fine, yet on others it baulks
at trying to put a
function straight into the event like above.

Am I doing anything wrong?

Cheers

Chris



_______________________________________________
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