Page 2 of 2 FirstFirst 12
Results 16 to 29 of 29
  1. #16
    pbaldy's Avatar
    pbaldy is offline Who is John Galt?
    Windows XP Access 2007
    Join Date
    Feb 2010
    Location
    Nevada, USA
    Posts
    22,521
    Why not just email it to me:

    removed to prevent spam
    Last edited by pbaldy; 03-07-2012 at 10:44 AM.
    Paul (wino moderator)
    MS Access MVP 2007-2019
    www.BaldyWeb.com

  2. #17
    pbaldy's Avatar
    pbaldy is offline Who is John Galt?
    Windows XP Access 2007
    Join Date
    Feb 2010
    Location
    Nevada, USA
    Posts
    22,521
    Your basic problem is that the data is in a subform, not the form the code is in. This works:

    Me.Sub_Frm_ScheduledMealsByCategoryChild.Form.Filt er = "MealName = 'corn dogs - adult'"
    Me.Sub_Frm_ScheduledMealsByCategoryChild.Form.Filt erOn = True
    Paul (wino moderator)
    MS Access MVP 2007-2019
    www.BaldyWeb.com

  3. #18
    Phred is offline Competent Performer
    Windows 7 64bit Access 2007
    Join Date
    Dec 2009
    Posts
    246

    Basic Help and Questions on Filtering

    I continue to have problems with filtering. As I continue to read I think it is something basic I am missing as I have never used filters before.

    I see "Filter" in the property page for Tables, forms, queries, and VB coupled with several different kinds of methodology. But no information on the method that is best for my situation.

    It seems I need to create a filter and save it somewhere and then I can toggle it on and off.

    My code seems to be right. Here are my basic questions:

    Do I need to create and save a filter first? If so, where? and by what method?

    Do I then activate the filter and deactivate the filter from VBA? Or is everything created within the code in VBA? See above.

    I want to split and compile the database. Does this impact where and how I create the filter?

    Can anyone see what I am missing?

    I can make a filter run from the ribbon and have it filter and unfilter so I know it will work.

    I have read every article everyone has suggested so far and any I can find on my own as well as my books.

    I have a delivery date of this comming Monday so I am feeling pressure. This is the last item on my to do list.

    Thanks all for bearing with me on this. Fred

  4. #19
    Phred is offline Competent Performer
    Windows 7 64bit Access 2007
    Join Date
    Dec 2009
    Posts
    246

    Some Progress

    I deleted all of my code under my filter button. I pasted back in only PBaldy's code as above.

    Dim StartDate As Date, EndDate As Date
    StartDate = Me.FilterDateStart
    EndDate = Me.FilterDateEnd
    Me.Filter = "[DateAssigned] >= #" & StartDate & "# AND [DateAssigned] <= #" & EndDate & "#;"
    Me.FilterOn = True

    I returned to the form and entered the dates 3/7/2012 and 3/9/2012.

    I clicked the button and something actually happened. The data form filtered but it did not filter by the dates I put on the form. It filtered retaining 3/7/2012 - 3/15/2012

    Click image for larger version. 

Name:	Filter2.JPG 
Views:	9 
Size:	46.9 KB 
ID:	6673

    I put a watch on the variables and the dates are being captured right. I noticed it is returning 1/2 of the records in the table which consists of March 2012.

    1. This is the first time it worked at all. I don't know why it worked.

    2. Could it be returning a previous filter date range?

    3. After filtering the Togle button on the ribbon activates. If I click it I get an error "Syntax Error in Query Incomplete Query Clause."

    4. In the Filter Off button I created On Click:

    me.filteron=false

    It doesn't do anything. What would be the code to restore this to the unfiltered state?

    Thanks Fred

  5. #20
    pbaldy's Avatar
    pbaldy is offline Who is John Galt?
    Windows XP Access 2007
    Join Date
    Feb 2010
    Location
    Nevada, USA
    Posts
    22,521
    The code I posted above (disregarding the spaces added by the forum) worked fine, so your task should simply be one of building a valid filter string. You haven't said what your "problems" are now, so not sure how to point you. In answer to your questions, no you don't have to create a filter first. In a split db the code would be in the front end, so no effect on how you create it.

    The sample db in this FAQ demonstrates a somewhat similar method, but it sets the row source of the subform rather than the filter. Frankly either should work fine.

    http://www.baldyweb.com/BuildSQL.htm
    Paul (wino moderator)
    MS Access MVP 2007-2019
    www.BaldyWeb.com

  6. #21
    pbaldy's Avatar
    pbaldy is offline Who is John Galt?
    Windows XP Access 2007
    Join Date
    Feb 2010
    Location
    Nevada, USA
    Posts
    22,521
    I don't know if you're working with something different than you sent me. This works:

    Dim StartDate As Date, EndDate As Date
    StartDate = Me.FilterStartDate
    EndDate = Me.FilterEndDate
    Me.Sub_Frm_ScheduledMealsByCategoryChild.Form.Filt er = "[DayAssigned] >= #" & StartDate & "# AND [DayAssigned] <= #" & EndDate & "#"
    Me.Sub_Frm_ScheduledMealsByCategoryChild.Form.Filt erOn = True

    Noting that your form control names are different, the data field name is different, and you still haven't referred to the subform.
    Paul (wino moderator)
    MS Access MVP 2007-2019
    www.BaldyWeb.com

  7. #22
    Phred is offline Competent Performer
    Windows 7 64bit Access 2007
    Join Date
    Dec 2009
    Posts
    246

    Date seen as time

    John I seem to be having some real problems with navigating the forum. I just found your response from yesterday. Thanks so much for responding. I think you are right.

    I made an error in this posting so I have edited the info.

    My DayAssigned is coming up as a time and my StartFilterDate and EndFilterDate are comming up as short dates. So far everywhere I look DayAssigned is set as a short date. But as a result I get this error:

    Click image for larger version. 

Name:	DateError.JPG 
Views:	8 
Size:	19.2 KB 
ID:	6678

    I am going through everything to make sure the DayAssigned is a short date but I'm not finding a problem so far. Is there a way for force it to display date instead of time in the code? I have read the articles on dates but don't see anything that I understand since it is already in a short date format.

    Is it possible that the [DayAssigned] in the expression is being read as time and needs [#" DayAssigned #"] or some variation on that, that forces it to be seen as a date? I have gone through everything I can find an it is set as a short date.

    Thanks Fred
    Last edited by Phred; 03-08-2012 at 02:32 PM. Reason: Update in information

  8. #23
    pbaldy's Avatar
    pbaldy is offline Who is John Galt?
    Windows XP Access 2007
    Join Date
    Feb 2010
    Location
    Nevada, USA
    Posts
    22,521
    I'll reply in case "John" isn't around.

    It appears that the dates aren't coming through from the textboxes (0 could be represented like that). I don't think you want the semi-colon either. Did you try what I posted? It worked in the db you sent me. You're saying DayAssigned in your text but the error has DateAssigned.
    Paul (wino moderator)
    MS Access MVP 2007-2019
    www.BaldyWeb.com

  9. #24
    Phred is offline Competent Performer
    Windows 7 64bit Access 2007
    Join Date
    Dec 2009
    Posts
    246

    Eliminated semi-colon cleared up time error.

    Yes, I implemented your code immediately. I deleted everything in the module and pasted your code in verbatim. I noticed the discrepancy between the DateAssigned and DayAssigned and corrected for it. I still got the time error so I eliminated the semi-colon and the "time" error went away. I get no error messages now. The filter runs without any error but it now filters out all the records.

    I added records for the first week of April and set the filter dates to show between 4/1/2012-4/7/2012, clicked to filter and all records vanished from the screen. If I click my remove filter button all the records come back. DoCmd.RunCommand (acCmdRemoveFilterSort)

    So I don't think it is picking up the filter dates either. Here is the code as it sits right now:
    Dim StartDate As Date, EndDate As Date

    Me.Sub_Frm_ScheduledMealsByCategoryChild.Form.Filt er = "[DayAssigned] >= #" & StartDate & "# AND [DayAssigned] <= #" & EndDate & "#"

    Me.Sub_Frm_ScheduledMealsByCategoryChild.Form.Filt erOn = True

    You don't give your name but thanks for your help. I'm going to see if I can set up watches on the variables and confirm what is comming through.

    Fred
    __________________________________________

    I set

    StartDate=StartDate

    EndDate=EndDate

    I set watches on both and they each showed up in the Watch as time 12:00 and not dates. So the same problem exists I am getting the time portion of the date field only even though they are set as ShortDate.
    Last edited by Phred; 03-08-2012 at 03:52 PM. Reason: Tested Variables

  10. #25
    pbaldy's Avatar
    pbaldy is offline Who is John Galt?
    Windows XP Access 2007
    Join Date
    Feb 2010
    Location
    Nevada, USA
    Posts
    22,521
    My name (Paul) is in my sig, which unfortunately the forum drops from some posts. Not sure what to say, as that code works fine for me. See attached.

    Click image for larger version. 

Name:	Filtering.jpg 
Views:	12 
Size:	82.0 KB 
ID:	6680
    Paul (wino moderator)
    MS Access MVP 2007-2019
    www.BaldyWeb.com

  11. #26
    Phred is offline Competent Performer
    Windows 7 64bit Access 2007
    Join Date
    Dec 2009
    Posts
    246
    Hi Paul:

    Thanks for your efforts. I placed your code in my chopped down version I sent you and had the same problem. I moved the chopped down version to another machine and still had the same problem. All the records are filtered out. So I'm stumped.

    Could we pull it apart with DatePart in vb and see if we could reassemble it with the date or is that just wishfull thinking. Is there any way to do this with queries? The subform is based on a query and I can't put another criteria in it. Is there anyone else you can think of that might have some insight?

    Thanks so much.

    Fred

  12. #27
    Phred is offline Competent Performer
    Windows 7 64bit Access 2007
    Join Date
    Dec 2009
    Posts
    246

    Fixed it, Forced Time to Date with Additional Variables

    To all the split personalities of John Gault:

    I added two additional variables not influenced whatsoever by the bad binary karma that is haunting me. This works perfect:

    Dim dtstart As Date, dtend As Date

    dtstart = Me.StartDate

    dtend = Me.EndDate

    Me.Sub_Frm_ScheduledMealsByCategoryChild.Form.Filt er = "[DayAssigned] >= #" & dtstart & "# AND [DayAssigned] <= #" & dtend & "#"

    Me.Sub_Frm_ScheduledMealsByCategoryChild.Form.Filt erOn = True

    Phred the Phabulous

  13. #28
    Phred is offline Competent Performer
    Windows 7 64bit Access 2007
    Join Date
    Dec 2009
    Posts
    246
    Dear Syble: Honestly, it was all you guys/gals inside John Gault that put me on the right track.

  14. #29
    pbaldy's Avatar
    pbaldy is offline Who is John Galt?
    Windows XP Access 2007
    Join Date
    Feb 2010
    Location
    Nevada, USA
    Posts
    22,521
    Ah, that's where you got the "John" from. That's a book character. Glad you got it working!
    Paul (wino moderator)
    MS Access MVP 2007-2019
    www.BaldyWeb.com

Page 2 of 2 FirstFirst 12
Please reply to this thread with any new information or opinions.

Similar Threads

  1. Filter form with command button
    By NISMOJim in forum Forms
    Replies: 6
    Last Post: 10-22-2011, 02:29 AM
  2. Filter button w/ pop-up dialog?
    By 10 Gauge in forum Forms
    Replies: 1
    Last Post: 07-19-2011, 07:04 AM
  3. Replies: 3
    Last Post: 10-22-2010, 06:53 PM
  4. Button hiding when filter on
    By rstonehouse in forum Forms
    Replies: 2
    Last Post: 08-25-2010, 06:24 AM
  5. Filter button
    By tomeem in forum Access
    Replies: 0
    Last Post: 08-28-2009, 12:50 AM

Tags for this Thread

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts
  •  
Other Forums: Microsoft Office Forums