Tek-Tips is the largest IT community on the Internet today!

Members share and learn making Tek-Tips Forums the best source of peer-reviewed technical information on the Internet!

  • Congratulations SkipVought on being selected by the Tek-Tips community for having the most helpful posts in the forums last week. Way to Go!

Filter Button on Form 2

Status
Not open for further replies.

woodyinoz

IS-IT--Management
Jan 8, 2002
215
0
0
GB
I want to put a button on my form which carries out a similar function to the filter icon. I want the user be able to filter 2 of the fields present on the form in order to narrow down the information shown. I.e. enter contract number and structure number.

Thanks again

Woody
 
Hope this works or at least points you in the right dirrection.

method pushButton(var eventInfo Event)
dodefault
ContractNo.moveto()
MenuAction(MenuFieldFilter)
endMethod
 
Having tried this code it works lovely. How do you clear the filter without bringing up the dialog box? I have programmed a button using the code to show a filtered table frame, filtered on the surname I have entered. I can then select the client from the table frame & process accordingly. When finished I would like to clear the filter so that the table frame shows the whole database. If this can be done on the same button, even better.
Many thanks,

Lewy
 
Lewy,

Well, here's one way to do it:

Code:
method pushButton(var eventInfo Event)
var
   astrNames  Array[] String
   pmFilter,
   pmFields   PopupMenu
   siCounter  SmallInt
   strChoice  String
   uiMaster   UIObject
endVar

const
   DROPFILTER = "&Drop Filter"
endConst

;// Attach uiMaster to object bound to
;// form's master table.
uiMaster.attach( "Customer" )
uiMaster.enumFieldNames( astrNames )

;// create popup menu for field names
for siCounter from 1 to astrNames.size()
   pmFields.addText( astrNames[ siCounter ] )
endFor

;// create and display popup menu for button
pmFilter.addPopup( "&Filter On", pmFields )
pmFilter.addSeparator()
pmFilter.addText( DROPFILTER )

strChoice = ""
strChoice = pmFilter.show()

;// evaluate user's choice
switch

   case strChoice = "" :
      ;// do nothing, as user cancelled menu.

   case strChoice = DROPFILTER :

      uiMaster.dropGenFilter()
      uiMaster.setRange()

   otherwise : ; check for valid fieldname to filter on

      if astrNames.contains( strChoice ) then

         uiMaster.attach( uiMaster.FirstRow )
         uiMaster.enumObjectNames( astrNames )
         for siCounter from 2 to astrNames.size()
            uiMaster.attach( astrNames[ siCounter ] )
            if uiMaster.FieldName = strChoice then
               strChoice = astrNames[ siCounter ]
               uiMaster.MoveTo()
               uiMaster.menuAction( menuFieldFilter )
               quitLoop
            endIf
         endFor

      else

         msgStop( "Unhandled Menu Command",
                  "I don't know how to handle the \"" +
                  strChoice + "\" command.  Please " +
                  "contact support." )

      endIf

endSwitch

endMethod

Now, you'll note that this:

1. Was designed just to handle single table forms,

2. Assumes the master table appears as a repeating object on the form (e.g. a table frame or MRO),

3. Hard codes the name of the master table object.

It also has a bit of unnecessary code, if you plan to use it heavily; there's no reason you couldn't populate the popup menus during the form's init() event or the button's open() event.

Hope this helps...

-- Lance
 
I quite agree....Thanks Lance. I have made one modification and that is to alter the sicounter loop to go from 5 to 5 (in my case) so that I can just filter on the Lastname field. I can now see many possiblities ahead of me.

regards,

Lewy
 
Status
Not open for further replies.

Part and Inventory Search

Sponsor

Back
Top