[AccessD] Your favorite control behavior

John W. Colby jwcolby at colbyconsulting.com
Sun Mar 7 06:56:23 CST 2004


>That is almost exactly the way my Notinlist procedure is coded.  I also add
two parameters, one for the target table to which the record will be added
and one for a user name for the type of data to be added.

My framework has this functionality built in.  The developer programs the
framework for each such control in the form's OnOpen with syntax like:

    With fclsfrm.Children
        .Item("cboIDCity").NotInListData "tlkpCity", "CI_Name", "lfrmCity"
        .Item("cboIDPrefix").NotInListData "tlkpPrefix", "PFX_Prefix",
"lfrmPrefix"
        .Item("cboIDSuffix").NotInListData "tlkpSuffix", "SFX_Suffix",
"lfrmSuffix"
        .Item("cboIDCity").DependentSet fclsfrm.Children("cboIDContactCity")
        .Item("cboIDST").DblClickFormData = "lfrmState"
        .Item("cboIDContactCity").NotInListData "tlkpCity", "CI_Name",
"lfrmCity"
        .Item("cboIDContactSt").DblClickFormData = "lfrmState"
        .Item("cboIDContactCity").DependentSet fclsfrm.Children("cboIDCity")
    End With

This is actual code taken from the Open of a form in an application.  You
can also see the calls to set up "dependent object processing" for combos
that have other combos that need requerying when they are changed.

For the NotInList processing, as you can see I specify the combo name to
find the class for in a collection of classes - .Item("cboIDCity"), then
specify a method of that class that I will pass parameters into -
.NotInListData, then pass in the table name, field name, and a form to open
if the double click is used.  If the form is missing, the double click is
disabled.  If the table and field are missing but the form is there, then
the NotInList is disabled.  There are tables that a combo can display data
from that have multiple fields that may need editing.

In addition, my code that opens the form takes the PK of the item currently
selected and looks up that record, so that when the form opens it is already
on that record waiting to be edited.

>I just set a single record recordset for the existing form to the record
that is added and it displays the new data in the appropriate field or
fields.

I tried doing multi-field parsing and such and it just got too messy and
confusing to the user.  If the table has multiple fields, I open an edit
form, take the data the user just typed that wasn't in list and make that
data the "default value" of the control on the form for the data displayed
in the combo.  For example if the user is typing in an SSN of a person ad it
is not in list, there are waaaay to many fields to fill in for a new person
to just do it without a form, so I open the form in Add mode, and place that
SSN in the ssn field on the form.

This is all done using the combo control class communicating with the form
class.  The control class opens the new form and passes in OpenArgs.  The
form class discovers it has openargs, loads an OpenArgs class which parses
the OpenArgs and processes any standard OpenArgs such as the one to find the
control and make the data the DefaultValue.

>in the On Got Focus entry in the property you could enter:
=OnFocus([Screen].[Activecontrol])

Unfortunately doing things that way has several major drawbacks.

1) You can't use the Find in a code module to find everywhere that function
is called since the call to the function isn't in code.  I realize that it
can be found from a search utility such as speedferret or Find and Replace
but that means that you now have to switch focus and go to that utility.

2) You can't add other functionality to that event since you are specifying
that YOUR function be called.  There is no generic event stub for adding
additional processing to.

3) Programs such as my framework which need to hook events just write
MyCtl.SomeEvent = "[EventProcedure]" in order to hook the event and cause
Access to route processing to the event stub.  Your custom processing would
just disappear now.

Using this method is fine if you are the only developer who will ever touch
your app (and unfortunately many developers simply don't care about the guy
that comes along behind).  You know you do that, you love doing that and you
are happy with it.  God forbid you get hit by a bus and I have to take over
maintenance of your app because I will be cursing your name for the rest of
the life of that application (or until I get the mess straightened out).

>Another nice means to hookup events automatically is to create a control
combination, or even a single control, encapsulated on a sub form all by
itself.

My only problem with using subforms in this manner is the frustration of
getting the cursor movement to work correctly.  The user is tabbing along
filling in data and hits a subform and has to then use special keys to get
out of the thing and into the next control to be filled in.  A custom class
that has all the required processing that your form class has gives me all
(most) of the advantages that you mention without the "cursor movement"
issues since the control is now in my main form.  The only thing I don't get
is the "drag and drop and I'm done".  I do have to dimension the class,
initialize it, and clean it up when I am done.  I am so used to using
classes now though that this is a 60 second thing.

On the other hand, if this really is so generic that I use it all the time,
I use a naming convention such that as a combo or list class loads it looks
at it's name and hooks in the calls to that class to do the special
processing for it.  Then you are right back to drag and drop convenience.  I
do this for the record selector combos at the top of my forms.  They use a
naming convention and my combo class just "knows" that this is a record
selector and when an item is selected in that combo the combo class finds
the record selected and causes the form to display it.

John W. Colby
www.ColbyConsulting.com

-----Original Message-----
From: accessd-bounces at databaseadvisors.com
[mailto:accessd-bounces at databaseadvisors.com]On Behalf Of Jürgen Welz
Sent: Sunday, March 07, 2004 1:09 AM
To: accessd at databaseadvisors.com
Subject: RE: [AccessD] Your favorite control behavior


That is almost exactly the way my Notinlist procedure is coded.  I also add
two parameters, one for the target table to which the record will be added
and one for a user name for the type of data to be added.  I guess the only
difference is that I don't open a separate data entry form.  I just set a
single record recordset for the existing form to the record that is added
and it displays the new data in the appropriate field or fields.

For things like date fields or lookups, I create them once on a template
form and then copy from there to the form on which I need it displayed.
Although you can use WithEvents and hook up controls, I haven't found a way
to do this with the Notinlist parameters.  I have found that just about
every event that I may want to use WithEvents for, I can instead create a
public function procedure for.  For a control that displays a date for which
I want a calendar to pop on double click and to change backcolor when it
gets focus and revert to a non-focus backcolor when focus is lost, or
respond to mouse move events, I can call the public procedure, usually
passing in screen.activecontrol by using the function name rather than
[eventprocedure] in the property sheet.  When I copy and paste a date
control from my template form into a new target form, it is completely
hooked up to all standard events.  Retrieving the form container name only
requires the code to check the parent property of the active control.  For
example, if you open the event property sheet for a conventional textbox, in
the On Got Focus entry in the property you could enter:

=OnFocus([Screen].[Activecontrol])

and in the On Lost Focus entyr you could enter:

=OffFocus([Screen].[Activecontrol])

Then in a public module:

Public Function OnFocus(ctl As Control)
    ctl.BackColor = vbWhite 'or some standard constant
End Function
Public Function OffFocus(ctl As Control)
    ctl.BackColor = -2147483633 'or some constant that can be set
End Function

You can check for control type being a combo and call .DropDown in the
OnFocus or write a separate OnFocusCombo procedure.  The whole point is that
the event procedures are hooked up  when you paste a copy of the control as
the event properties are copied with the control.

Another nice means to hookup events automatically is to create a control
combination, or even a single control, encapsulated on a sub form all by
itself.  The control comes with its own class module in the code behind the
subform.  I have found this a great way to hookup something like a callback
based list of municipalities with a not in list that can be made aware of
the need to requery the data array when there is an addition or change to a
municipality record.  No need to create a new copy of the control on
multiple forms, just drag the subform container on and you get format and
events all done.

Ciao
Jürgen Welz
Edmonton, Alberta
jwelz at hotmail.com





>From: "Arthur Fuller" <artful at rogers.com>
>Reply-To: Access Developers discussion and problem
>solving<accessd at databaseadvisors.com>
>To: "'Access Developers discussion and problem
>solving'"<accessd at databaseadvisors.com>
>Subject: RE: [AccessD] Your favorite control behavior
>Date: Sat, 6 Mar 2004 22:53:53 -0800
>MIME-Version: 1.0
>Received: from mc2-f12.hotmail.com ([65.54.190.19]) by mc2-s14.hotmail.com
>with Microsoft SMTPSVC(5.0.2195.6824); Sat, 6 Mar 2004 19:56:23 -0800
>Received: from databaseadvisors.com ([209.135.140.44]) by
>mc2-f12.hotmail.com with Microsoft SMTPSVC(5.0.2195.6824); Sat, 6 Mar 2004
>19:56:23 -0800
>Received: from databaseadvisors.com (databaseadvisors.com
>[209.135.140.44])by databaseadvisors.com (8.11.6/8.11.6) with ESMTP id
>i273tWM26752;Sat, 6 Mar 2004 21:55:32 -0600
>Received: from
>fep03-mail.bloor.is.net.cable.rogers.com(fep03-mail.bloor.is.net.cable.roge
rs.com
>[66.185.86.73])by databaseadvisors.com (8.11.6/8.11.6) with ESMTP id
>i273tRM26707for <accessd at databaseadvisors.com>; Sat, 6 Mar 2004 21:55:27
>-0600
>Received: from rock ([24.153.60.144])by
>fep03-mail.bloor.is.net.cable.rogers.com(InterMail vM.5.01.05.12
>201-253-122-126-112-20020820) with ESMTP
>id<20040307035516.YGWF411419.fep03-mail.bloor.is.net.cable.rogers.com at rock>
for
><accessd at databaseadvisors.com>; Sat, 6 Mar 2004 22:55:16 -0500
>X-Message-Info: jl7Vrt/mfsqz8S4A4C6FS1y0F6nk0vr4
>Message-ID: <016a01c40410$f433f490$6501a8c0 at rock>
>X-MSMail-Priority: Normal
>X-Mailer: Microsoft Outlook, Build 10.0.2627
>X-MimeOLE: Produced By Microsoft MimeOLE V6.00.2800.1165
>In-Reply-To: <DCEFJAOENMNENLAAOFGPGEFLHBAA.jwcolby at colbyconsulting.com>
>X-Authentication-Info: Submitted using SMTP AUTH LOGIN
>atfep03-mail.bloor.is.net.cable.rogers.com from [24.153.60.144]using ID
><artful at rogers.com> at Sat, 6 Mar 2004 22:55:16 -0500
>X-BeenThere: accessd at databaseadvisors.com
>X-Mailman-Version: 2.1.4
>Precedence: list
>List-Id: Access Developers discussion and problem
>solving<accessd.databaseadvisors.com>
>List-Help: <mailto:accessd-request at databaseadvisors.com?subject=help>
>List-Post: <mailto:accessd at databaseadvisors.com>
>List-Subscribe:
><http://databaseadvisors.com/mailman/listinfo/accessd>,<mailto:accessd-requ
est at databaseadvisors.com?subject=subscribe>
>List-Archive: <http://databaseadvisors.com/pipermail/accessd>
>List-Unsubscribe:
><http://databaseadvisors.com/mailman/listinfo/accessd>,<mailto:accessd-requ
est at databaseadvisors.com?subject=unsubscribe>
>Errors-To: accessd-bounces at databaseadvisors.com
>Return-Path: accessd-bounces at databaseadvisors.com
>X-OriginalArrivalTime: 07 Mar 2004 03:56:23.0073 (UTC)
>FILETIME=[27FAB110:01C403F8]
>
>I have a function called aaNotInList() which takes the same parms as the
>NotInList function and adds two new ones -- the name of the form to open
>when adding an item, and the "human" name of said entity, the latter
>just to pretty up the messagebox that comes up. The functon asks if you
>want to add a new "XXX" (4th parm) and if so opens the specified form,
>which uses the typical code to hide itself on OK and close itself on
>Cancel. Then the function does the usual "add to list and accept the
>value" and closes the form. It works great but I still have to type in
>that line of code every time I need one. Not that one line of code is a
>major hassle, I guess, but can you think of a class-based way to do
>this? It might be more fun to do it that way.
>
>Arthur
>
>-----Original Message-----
>From: accessd-bounces at databaseadvisors.com
>[mailto:accessd-bounces at databaseadvisors.com] On Behalf Of John W. Colby
>Sent: Saturday, March 06, 2004 1:24 PM
>To: AccessD
>Subject: [AccessD] Your favorite control behavior
>
>
>I am taking suggestions for control behaviors that you have found useful
>and have programmed controls to perform in the past.
>
>For example I program the back color of combos, lists and text boxes to
>change to a given color as they get the focus, and back to their
>original color as they lose the focus.  This helps to avoid the "where's
>the cursor" questions.
>
>Another example, I program the double-click of a combo to open a form to
>allow editing the data in the table that the combo pulls from.  In
>addition, if a combo is programmed to perform this behavior, I
>dynamically set its label's back color to a specific color.  this is a
>visual cue that "this combo has the dbl-click behavior activated"
>
>What kinds of things do you have your controls do?
>
>John W. Colby
>www.ColbyConsulting.com
>
>
>--
>_______________________________________________
>AccessD mailing list
>AccessD at databaseadvisors.com
>http://databaseadvisors.com/mailman/listinfo/accessd
>Website: http://www.databaseadvisors.com
>
>--
>_______________________________________________
>AccessD mailing list
>AccessD at databaseadvisors.com
>http://databaseadvisors.com/mailman/listinfo/accessd
>Website: http://www.databaseadvisors.com

_________________________________________________________________
Free yourself from those irritating pop-up ads with MSn Premium. Get 2months
FREE*
http://join.msn.com/?pgmarket=en-ca&page=byoa/prem&xAPID=1994&DI=1034&SU=htt
p://hotmail.com/enca&HL=Market_MSNIS_Taglines

--
_______________________________________________
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