7 Replies Latest reply on Nov 4, 2009 11:57 AM by ChrisB

    Search

    ChrisB

      Title

      Search

      Post

      What is the best way to accomplish this?

       

      User posts an entry on Home Layout Screen

      With the following fields

       

      Date

      Topic

      Project

      Information

       

      also on layout screen is a search button, and new entry button

       

      User clicks search button, which brings up the Search Layout Screen.

       

      Fields,

       

      From Date_______

      To Date________

       

      Search Button

      Home Button

       

      _________________________________

       

      I need the user to be able to search and find all of the records that are between the from date and the to date. I know this is really basic stuff and probable involves and, if, or statements but I dont know how to make it work.

       

       

      Filemaker 10

      OS X 10.6.1

       

      Thanks 

       

      Chris

        • 1. Re: Search
          ninja
            

          Howdy Chris,

           

          no if's...just variables.

           

          Assuming that the fields on your search layout are "fromdate" and "todate" (these fields shouldn't be used for anything but this search).  Also, consider making the fields global...but only if necessary.

           

          Your script would look like:

          SetVariable [$from; Value=Table::fromdate]

          SetVariable [$to; Value=Table::todate]

          GotoLayout [##the layout you want the results to be shown in##]

          Enter find mode

          Setfield [Table:: Date ; $from & "..." & $to ]

          Set ErrorCapture [on]

          Perform Find

           

          If you want to have a dialog for no found records, add:

          If ( Get(FoundCount) = 0 )

              Show Custom Dialog  ##whatever you want to say##

              Show All Records

          Endif
          SetField [ fromdate ; "" ]

          SetField [ todate ; "" ]

           

           

          Okay, one "if"...

          • 2. Re: Search
            philmodjunk
              

            Actually, global fields can be a slightly better way to do this.

             

            Then Ninja's script becomes:

             

            GotoLayout [##the layout you want the results to be shown in##]

            Enter find mode

            Setfield [Table:: Date ; YourTable::gFrom & "..." & YourTableg::To ]

            Set ErrorCapture [on]

            Perform Find

             

            If you want to have a dialog for no found records, add:

            If ( Get(FoundCount) = 0 )

                Show Custom Dialog  ##whatever you want to say##

                Show All Records

            Endif

            One of the advantages here is that you can save the criteria for each user (Different users searching at the same time won't lock each other out of global fields) and display it as part of the search results in the header or somewhere else that works for you. This can be very helpful to the user when they perform a search and don't get the results they expect.

            • 3. Re: Search
              ninja
                

              Yup,

               

              both work...I figure it's a preference thing.  The last two steps of my script clear the fields back out after the find.

               

              I dream that one day FMP will make globals actually "global" and prefer to live as if they were that way now.  FMP's global definitions are limited to a single user in thier own world (globe)...but I digress.

               

              Hey, I never claimed to be well adjusted ;)

              • 4. Re: Search
                philmodjunk
                  

                "FMP's global definitions are limited to a single user in their own world (globe)"

                 

                I find that to be the very best feature of globals--especially for the above search example when the database has multiple simultaneous users.

                 

                consider this scenario when using Non global search fields and your (Ninja's) script:

                 

                User one navigates to record ABC and starts a search by entering search criteria in the local fields. Before actually clicking the button to trigger the script, User two navigates to record ABC and starts entering search criteria. User one now clicks search.

                 

                Depending on exactly when each user is doing what, User two may get a record lock error message when they try to change User One's search criteria (and it's visible to them to see BTW) or User one may get completely unexpected results, (User one commits the record before starting the search), when his script uses search Criteria entered by User two.

                 

                In either case, this very feature of how global fields work in networked environments prevents these issues when you use global fields instead.

                • 5. Re: Search
                  ChrisB
                    

                  Thanks for the help guys!

                   

                  When I modify the fields to be global, and enter find mode the search to and from fields on the layout window seem to lock out. This also happens when I enter find mode without a script. If I change the fields back to non global I can enter the field on the layout with no problem.

                   

                  any ideas?

                   

                  Thanks!

                  • 6. Re: Search
                    philmodjunk
                       By "lock out" you mean you can't enter the field? That's correct. Filemaker will not allow you to enter data into a global field while in find mode. (If you think about it that makes no sense anyway.) Edit the field in browse mode before entering find mode and it'll work. (The script, anyway.)
                    • 7. Re: Search
                      ChrisB
                         That did it! thanks!