Alpha Video Training
Results 1 to 16 of 16

Thread: Filtered Browse By Date Range

  1. #1
    Member
    Real Name
    Mark Buonagurio
    Join Date
    Jun 2006
    Posts
    10

    Default Filtered Browse By Date Range

    A5 V5 - I've got an embedded browse on a form that contains a date field, let's call it "Transdate". I've added 2 date variable fields to the form named "StartDate" and "EndDate". I want to be able to enter a date range in the 2 variables, hit a button, and have the browse only display the records that fall within the range. How do I get this accomplished? I will also need a button to reset back to displaying all the records.

    Thanks In Advance

    MSB

  2. #2
    "Certified" Alphaholic
    Real Name
    Tom Baker
    Join Date
    Jun 2006
    Location
    Near Cherry Hill, NJ
    Posts
    1,296

    Default Re: Filtered Browse By Date Range

    Try this

    the OnPush event for the button to find the startdate and the enddate

    Code:
    dim tbl as p
    dim qry as p
    tbl=table.current()
    query.filter="(Transdate >= Var->startdate  )  .and. (Transdate <= Var->enddate  )"
    query.order=""
    qry=tbl.query_create()
    topparent:browse1.refresh_layout()
    qry.drop()
    The OnPush event for the show all button

    Code:
    topparent.show_all()
    topparent.fetch_first()
    Tom

  3. #3
    "Certified" Alphaholic
    Real Name
    Tom Cone Jr
    Join Date
    Apr 2000
    Location
    Florida
    Posts
    23,308

    Default Re: Filtered Browse By Date Range

    Tom,

    It's possible his form is based on a set of tables. Mark hasn't told us whether the browse is displaying parent or child records. This could change the code requirements, right?

  4. #4
    "Certified" Alphaholic
    Real Name
    Tom Baker
    Join Date
    Jun 2006
    Location
    Near Cherry Hill, NJ
    Posts
    1,296

    Default Re: Filtered Browse By Date Range

    Tom C

    You are right - the code I show in my post is based on a single table - not a set.

    The code would have to be changed if the browse is displaying child records.

    Was watching the returns last night and took a short break and replied to this post - in my haste to get back to the returns - I didn't read the post carefully. Mea culpa

    Thanks for the heads up.

    Tom B

  5. #5
    "Certified" Alphaholic
    Real Name
    Tom Cone Jr
    Join Date
    Apr 2000
    Location
    Florida
    Posts
    23,308

    Default Re: Filtered Browse By Date Range

    Hopefully, Mark will tell us more about his form, and the table or tables supporting it.

    -- tom

  6. #6
    Member
    Real Name
    Mark Buonagurio
    Join Date
    Jun 2006
    Posts
    10

    Default Re: Filtered Browse By Date Range

    You are correct Tom. There are 2 tables involved, a member table, and a transaction table. I created a set with the Member table as parent and a one to many link based on the memberID field. The form that contains the browse is based on this set. The browse contains some fields from the member table, and some from the transaction table. I hope this clarifies.

    Thanks.

  7. #7
    "Certified" Alphaholic
    Real Name
    Mike Christensen
    Join Date
    Nov 2005
    Location
    Michigan U.P.
    Posts
    5,937

    Default Re: Filtered Browse By Date Range

    Mark,
    Along with any info from Tom-Tom ( :) ), the easiest way I find to create filters, especially when what I try fails, is to let a genie do it for you to create the correct syntax. Using Action Scripting try the Custom Query--you may be able to just use this instead of learning xbasic....but even when using genies and Action Scripting to produce your scripts, form calling, etc., I highly recommend always checking out what was produced in xbasic to see how it is done as the sooner you are able to use a small amount of xbasic the more you will be able to modify a simple script into a more complex one that will be needed/required at some point in a database.

    Just some thoughts!
    Mike
    __________________________________________
    It is only when we forget all our learning that we begin to know.
    It's not what you look at that matters, it's what you see.
    Henry David Thoreau
    __________________________________________




  8. #8
    "Certified" Alphaholic
    Real Name
    Tom Cone Jr
    Join Date
    Apr 2000
    Location
    Florida
    Posts
    23,308

    Default Re: Filtered Browse By Date Range

    Here's one way to do it using Vers 9 of Alpha Five. Not sure if the queryrun() method is available in Vers 5.

    Assume form based on a set. The parent table is Members. The one to many child is Transactions. The link is on a "Member_id" field which is character data.

    Each Transaction table record has a "Trans_date" field, which is date data.

    There are two "session" level variables defined in the form layout. They are "vd_begin_date" and "vd_end_date", and they are date data, too.

    To filter the Transactions table to show only records which have Trans_date field values lying "between" the two variable dates, use this expression:


    Code:
    topparent.queryrun("between(Transactions->Trans_Date,Var->vd_begin_date,Var->vd_end_date)","","","No","Transactions",.f.)
    To see all the Transaction table records that are linked to each parent record use this expression:

    Code:
    topparent.queryrun("Transactions->Member_Id = Member_Id","","","No","Transactions",.f.)

  9. #9
    "Certified" Alphaholic
    Real Name
    Tom Baker
    Join Date
    Jun 2006
    Location
    Near Cherry Hill, NJ
    Posts
    1,296

    Default Re: Filtered Browse By Date Range

    Tom C

    queryrun() was available in Version 5

    Tom B

  10. #10
    Member
    Real Name
    Mark Buonagurio
    Join Date
    Jun 2006
    Posts
    10

    Default Re: Filtered Browse By Date Range

    Thanks. I'll give it a shot

  11. #11
    "Certified" Alphaholic Mike Wilson's Avatar
    Real Name
    mike wilson
    Join Date
    Apr 2005
    Location
    Grand Rapids, Michigan
    Posts
    4,188

    Default Re: Filtered Browse By Date Range

    Why does using a variable scoped as local produce an error and not work within the filter with queryrun()? See attached.
    Mike W
    __________________________
    "I rebel in at least small things to express to the world that I have not completely surrendered"

  12. #12
    Member
    Real Name
    Mark Buonagurio
    Join Date
    Jun 2006
    Posts
    10

    Default Re: Filtered Browse By Date Range

    Tom,

    The lines of code you sent work great. However, I needed to create a reverse set with the Transaction table as the parent to get all the records to show in the browse. When I had the Member table as the parent, the browse only displayed a single record. Any thoughts why? I've attached the database for you to take a look at.
    Last edited by MarkB; 11-06-2008 at 03:29 PM. Reason: Add attachment

  13. #13
    "Certified" Alphaholic
    Real Name
    Tom Cone Jr
    Join Date
    Apr 2000
    Location
    Florida
    Posts
    23,308

    Default Re: Filtered Browse By Date Range

    Mark, how about marking a trail to the parts of the database you want checked. Which form is not behaving as you wished? How do you want that particular form to behave?

    Also tell us about your set designs. I see you sometimes using Member_id, and sometimes a field called "Number". How do you want to link transactions to members?

    Last request... can you supply dummy transaction table records? This will make things easier on us, and will avoid problems that can happen if we enter field values that conflict with your field rules simply because we don't know your design.
    Last edited by Tom Cone Jr; 11-06-2008 at 03:53 PM.

  14. #14
    "Certified" Alphaholic Stan Mathews's Avatar
    Real Name
    Stan Mathews
    Join Date
    Apr 2000
    Location
    Bowling Green, KY
    Posts
    25,119

    Default Re: Filtered Browse By Date Range

    Quote Originally Posted by MarkB View Post
    When I had the Member table as the parent, the browse only displayed a single record. Any thoughts why?
    You have two members in the memb table with "number" 115. You only have one record for "memberid" "115" in the clubexpholding table. Thus a form based on the memberdetail set with memb as the parent will show the single clubexpholding record in the embedded browse linked to both parent records. You have no "many" child records linked to any parent record so no multiple browse records are shown.

  15. #15
    "Certified" Alphaholic Tim Kiebert's Avatar
    Real Name
    Tim Kiebert
    Join Date
    Jul 2004
    Location
    Geelong, Victoria, Australia
    Posts
    2,785

    Default Re: Filtered Browse By Date Range

    Quote Originally Posted by Mike Wilson View Post
    Why does using a variable scoped as local produce an error and not work within the filter with queryrun()? See attached.
    Mike, Here is my theory.

    Lets assume you are the CEO of a multi national company. (you are aren't you?)
    You want to find some correspondence concerning a price fixing meeting you had with one of you competitors.

    The actions you take are like your script (date_local_var)
    So you look up in your diary(the dialog box) to get the date of the meeting. You store that date in a spot in your mind (the local variable).
    Next you instruct your secretary (the queryrun function) to go find all the correspondence that matches the date you are thinking of. She attempts to carry out your instruction but complains bitterly "How am I supposed to know what to look for, am I a mind reader?"

    Revised actions as in (date_shared_var)

    So you look up in your diary(the dialog box) to get the date of the meeting. You store that date on a postit note and stick it to your forehead. (the shared variable).
    Next you instruct your secretary (the queryrun function) to go find all the correspondence that matches the date on the postit note. She attempts to carry out your instruction, sees the date on your forehead, and comes back with the files you need.



    Even though the queryrun function is run from the script where the local variable also is, the function is actually doing its thing against on object outside of the script. So when the function goes and does its thing it is no longer in the same room as the local variable. The function takes all the arguments you have given it and tries to resolve them at the point where it it is doing its work, which in this case is not within the script itself.

    You can still use a local variable but need to formulate the instruction a little different. The CEO needs to take what is stored in his mind (the local variable) and include it in the instruction to the his secretary, instead of telling the secretary where to find the date (in the variable, which in the case of the local variable she can't see).
    Like so:
    Code:
    
    records_found = topparent.queryrun("T_parent->P_date = " + s_quote(ctod(Var->vlocal_date)),"","","No","<Cross Level>",.f.)
    or
    records_found = topparent.queryrun("T_parent->P_date = " + s_quote(ctod(vlocal_date)),"","","No","<Cross Level>",.f.)
    or
    records_found = topparent.queryrun("T_parent->P_date = {" + vlocal_date+"}","","","No","<Cross Level>",.f.)
    Tim Kiebert
    Eagle Creek Citrus
    A complex system that does not work is invariably found to have evolved from a simpler system that worked just fine.

  16. #16
    Member
    Real Name
    Mark Buonagurio
    Join Date
    Jun 2006
    Posts
    10

    Default Re: Filtered Browse By Date Range

    Tom,

    I'll get you some more data today and resend. Thanks everyone for the response. This message board is awesome.

Similar Threads

  1. Range and date operations
    By lucasushi in forum Alpha Five Version 8
    Replies: 7
    Last Post: 11-02-2007, 09:30 PM
  2. Date range in report
    By BWilliams in forum Alpha Five Version 6
    Replies: 11
    Last Post: 11-09-2004, 10:39 AM
  3. Enter a date range
    By Scott Rusoff in forum Alpha Five Version 5
    Replies: 1
    Last Post: 02-10-2003, 08:12 AM
  4. Date Range Filter
    By Marc King - A5solutions in forum Alpha Five Version 5
    Replies: 8
    Last Post: 12-26-2002, 06:19 PM
  5. Date range for printing
    By Steve Conlin in forum Alpha Five Version 4
    Replies: 1
    Last Post: 04-22-2002, 02:19 PM

Bookmarks

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts
  •