[AccessD] Not-In-List Popup Form question - SOLVED

jwcolby jwcolby at colbyconsulting.com
Thu May 22 05:48:55 CDT 2008


Bob,

I have an OpenArgs class which can be used for all forms.

You can download a demo from my web site.  if you haven't already done 
so you will need to register, then log in.  Go to Example Code / 
Utilities, click C2DbOpenargs.  From my web site:

***

I pass openargs in the form Varname1=VarVal1;VarName2=VarVal2;etc=etc1; 
This is a syntax that has been around since early Access days and was 
used extensively by, and perhaps even "invented by" Ken Getz.  The = is 
used as the separator, the semicolon as the delimiter.

I wrote a pair of classes which handle my openargs.  A "control class" 
which I name OpenArgs (plural) grabs the openargs string and parses the 
varname and value for each openarg.  It then instantiates a OpenArg 
(singular) class to store this VarName and VarVal in.  VarName is a 
string type, VarVal is a variant type.  Making it Variant causes an 
automatic coerces ion in a lot of cases - currency values get turned 
into Currency variants, dates get turned into dates etc.  At any rate, 
each OpenArg instance is stored in a collection in the OpenArgs (plural) 
class.

The OpenArgs class is dimensioned in the form header, and instantiated 
in the OnOpen of the form.  By the time it finishes loading, all of the 
OpenArgs are parsed and sitting in OpenArg class instances in the 
collection in OpenArgs.  OpenArgs has a method for reading OpenArg 
instances from the collection.  OpenArg instances are stored in the 
collection keyed on the VarName.

Thus you have a pair of classes which automatically handles getting 
openargs for you, one or a hundred, it doesn't matter, and it doesn't 
have to be "re-invented" every time you want to get your openargs. 
Syntax is now standardized everywhere in your app.

The form of course must know what openargs it is expecting, so it can 
now simply call OpenArgs.Arg("VarName") and get back VarVal (a variant). 
  What the form does with the OpenArg is up to you, but getting the 
OpenArgs available to the form is trivial.

All of the code follows.  My clsOpenArgs (plural, the controller) also 
has the ability to automatically interpret openargs as properties fo the 
form.  In other words, if a param is passed in to clsOpenArgs that says 
to do so, then if an OpenArg VarName is the same as a property of the 
form, the form property is set to VarVal.  I have actually demoed this 
in the state form, where the form that opens frmState passes in the 
values for properties

strOpenArgs = "DataEntry=True;AllowEdits=True;AllowDeletions=False;"

The state form opens, the OpenArgs class parses the OpenArgs string 
passed in, discovers that I want it to use the openargs to set form 
properties, and does so.

Any OpenArgs which do not match the name of a form property are left 
uninterpreted and the form can use them for whatever purpose you choose. 
  You can also not tell clsOpenArgs to interpret the openargs as form 
properties, in which case all OpenArgs are left uninterpreted and you 
can do with them all as you will.

***

John W. Colby
www.ColbyConsulting.com


Bob Gajewski wrote:
> Kath
> 
> I have the .Cycle property set to 'All Records' because this is the normal
> maintenance form for the manufacturers table, However, your question *did*
> lead me to the answer - OpenArgs!
> 
> In the equipment form:
> 	...
> 	DoCmd.OpenForm "frmManufacturers", acNormal, , , acFormAdd,
> acDialog, "AddRecord"
> 	...
> 
> In the manufacturer form:
> 	Private Sub Form_Open(Cancel As Integer)
> 	If Not IsNull(Me.OpenArgs) Then
> 	    If Me.OpenArgs = "AddRecord" Then
> 	        Form.Cycle = 1
> 	    Else
> 	        Form.Cycle = 0
> 	    End If
> 	End If
> 	End Sub
> 
> 
> Thank you so much.
> Bob 
> 
> -----Original Message-----
> From: accessd-bounces at databaseadvisors.com
> [mailto:accessd-bounces at databaseadvisors.com] On Behalf Of Kath Pelletti
> Sent: Wednesday, May 21, 2008 23:46 PM
> To: Access Developers discussion and problem solving
> Subject: Re: [AccessD] Not-In-List Popup Form question
> 
> Bob - Do you have the 'cycle' property on the popup form set to 'Current
> record' as opposed to 'All Records'?
> 
> Kath
> ----- Original Message -----
> From: "Bob Gajewski" <rbgajewski at adelphia.net>
> To: "'Access Developers discussion and problem solving'" 
> <accessd at databaseadvisors.com>
> Sent: Thursday, May 22, 2008 1:39 PM
> Subject: [AccessD] Not-In-List Popup Form question
> 
> 
>> Hi Folks - me again  :(
>>
>> I am trying to figure out how to handle NotInList code to popup a form for
>> adding the new record; allowing the addition of only 1 record; then 
>> closing
>> the popup and returning the added value.
>>
>> I have an equipment table, and one of the fields is for the manufacturer. 
>> My
>> code below opens the form, allows for the addition of any number of 
>> entries,
>> then when manually closed it leaves the original value that fired the NIL
>> event. I can live with the manual popup form close, but I really want to
>> only allow a single record addition.
>>
>> Any suggestions are much appreciated!
>>
>> Regards,
>> Bob Gajewski
>>
>>
>>
> ============================================================================
>> =========
>>
>> Private Sub EquipmentManufacturerID_NotInList(NewData As String, Response 
>> As
>> Integer)
>> Dim db As Database, rs As Recordset
>> Dim strMsg As String
>> strMsg = "'" & NewData & "' is not in the Manufacturers table. "
>> strMsg = strMsg & "Would you like to add it?"
>> If vbNo = MsgBox(strMsg, vbYesNo + vbQuestion, "Add Manufacturer") Then
>>    Response = acDataErrDisplay
>> Else
>>    On Error Resume Next
>>    DoCmd.OpenForm "frmManufacturers", acNormal, , , acFormAdd, acDialog
>>    DoCmd.Save
>>    If Err Then
>>        MsgBox "An error occurred. Please Try Again."
>>        Response = acDataErrContinue
>>    Else
>>        Response = acDataErrAdded
>>        LastUpdated = Date
>>    End If
>>    Me!EquipmentManufacturerID.Requery
>> End If
>> strMsg = ""
>> End Sub
>>
>>
>> -- 
>> 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