Page 1 of 2 12 LastLast
Results 1 to 15 of 18
  1. #1
    Daryl2106 is offline Competent Performer
    Windows 7 32bit Access 2010 32bit
    Join Date
    Sep 2011
    Posts
    167

    Optional filtering (was More questions..)

    Hi,



    This is year two designing a DB for our adult learning department and with all the help I received last year from the forum the DB worked exceedingly well. We are now asking it to do more. So I have a lot of questions to ask over the next several weeks.

    Firstly, I have a table that stores all student information and a form based on that table to enter and review data. One of the fields I have is whether they are "ACTIVE" or not. We would like to be able to display only the active students from time to time on the form by clicking a check box. Do I have to create a new form or can I create a query or event and run it within the current form?

    Thanks and take care,

    Daryl

  2. #2
    RuralGuy's Avatar
    RuralGuy is offline Administrator
    Windows 7 64bit Access 2010 32bit
    Join Date
    Mar 2007
    Location
    8300' in the Colorado Rocky Mountains
    Posts
    12,922
    I have all of my forms bound to queries and when "Active" is an issue I have a CheckBox on the form for that and make the query aware of that control on the form through the Forms collection..

  3. #3
    Daryl2106 is offline Competent Performer
    Windows 7 32bit Access 2010 32bit
    Join Date
    Sep 2011
    Posts
    167
    Thanks.

    What if the form isn't based on a query. can you still filter records for "active" students?

  4. #4
    RuralGuy's Avatar
    RuralGuy is offline Administrator
    Windows 7 64bit Access 2010 32bit
    Join Date
    Mar 2007
    Location
    8300' in the Colorado Rocky Mountains
    Posts
    12,922
    Is there some reason you don't want to use a query? They are far more flexible and take up little or no room in a db.

  5. #5
    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 use this type of thing, which will work whichever the record source is:

    Code:
      If Me.chkShowRetired = True Then
         Me.FilterOn = False   
      Else
         Me.Filter = "Retired = False"
         Me.FilterOn = True
       End If
    I'm going to change your thread title to something more descriptive.

    Edit: that code would be in the after update event of the check box.
    Paul (wino moderator)
    MS Access MVP 2007-2019
    www.BaldyWeb.com

  6. #6
    Daryl2106 is offline Competent Performer
    Windows 7 32bit Access 2010 32bit
    Join Date
    Sep 2011
    Posts
    167
    It is just that I have a fairly large form linked directly to the table and I don't know how to create a query without having to completely rebuild the form

  7. #7
    orange's Avatar
    orange is offline Moderator
    Windows XP Access 2003
    Join Date
    Sep 2009
    Location
    Ottawa, Ontario, Canada; West Palm Beach FL
    Posts
    16,726

  8. #8
    RuralGuy's Avatar
    RuralGuy is offline Administrator
    Windows 7 64bit Access 2010 32bit
    Join Date
    Mar 2007
    Location
    8300' in the Colorado Rocky Mountains
    Posts
    12,922
    A Form cannot tell the difference between a table and a query. If you create a query that includes all of the fields of the table, you could then set it as the RecordSource of the Form and everything would just work with no other changes.

  9. #9
    Daryl2106 is offline Competent Performer
    Windows 7 32bit Access 2010 32bit
    Join Date
    Sep 2011
    Posts
    167

    Optional filtering

    Thanks so much for everything so far everyone. I just got back to this today.

    I tried the event procedure with the following code:

    Private Sub Check2107_AfterUpdate()

    If Me.Check2107 = True Then
    Me.FilterOn = False
    Else
    Me.Filter = "Check2107 = False"
    Me.FilterOn = True
    End If


    End Sub

    I am getting parameter box popping up when I "de-select" the check box. I will change the name to something more appropriate later. What did I do wrong?

    Thanks,

    Daryl

  10. #10
    pbaldy's Avatar
    pbaldy is offline Who is John Galt?
    Windows XP Access 2007
    Join Date
    Feb 2010
    Location
    Nevada, USA
    Posts
    22,521
    Is Check2107 the name of the field in the table? That's what Access is looking for there.
    Paul (wino moderator)
    MS Access MVP 2007-2019
    www.BaldyWeb.com

  11. #11
    Daryl2106 is offline Competent Performer
    Windows 7 32bit Access 2010 32bit
    Join Date
    Sep 2011
    Posts
    167
    The check box is not bound to a table. Does it need to be?

  12. #12
    pbaldy's Avatar
    pbaldy is offline Who is John Galt?
    Windows XP Access 2007
    Join Date
    Feb 2010
    Location
    Nevada, USA
    Posts
    22,521
    No, but the line setting the filter has to specify a field in the record source. You're telling Access what to filter on. It could also look like:

    Me.Filter = "Status = 'Active'"
    Paul (wino moderator)
    MS Access MVP 2007-2019
    www.BaldyWeb.com

  13. #13
    Daryl2106 is offline Competent Performer
    Windows 7 32bit Access 2010 32bit
    Join Date
    Sep 2011
    Posts
    167
    Hi and thanks,

    The field in the table is called "Active". The checkbox on the form is "Check2107".

  14. #14
    pbaldy's Avatar
    pbaldy is offline Who is John Galt?
    Windows XP Access 2007
    Join Date
    Feb 2010
    Location
    Nevada, USA
    Posts
    22,521
    So did you change it?
    Paul (wino moderator)
    MS Access MVP 2007-2019
    www.BaldyWeb.com

  15. #15
    Daryl2106 is offline Competent Performer
    Windows 7 32bit Access 2010 32bit
    Join Date
    Sep 2011
    Posts
    167
    I tried several times but I'm not great with code so I didn't get it to work. I'm not where to put the table field name.

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

Similar Threads

  1. Compile Error: Argument not optional
    By tariq1 in forum Programming
    Replies: 4
    Last Post: 08-11-2012, 01:06 PM
  2. Multiple Filtering Questions
    By Datech in forum Forms
    Replies: 1
    Last Post: 04-23-2012, 03:01 PM
  3. multiple optional criteria
    By TheShabz in forum Programming
    Replies: 7
    Last Post: 07-05-2011, 05:13 PM
  4. Compile Error: Argument Not Optional
    By bg18461 in forum Access
    Replies: 1
    Last Post: 12-01-2010, 08:47 AM
  5. Skipping optional arguments
    By canfish in forum Programming
    Replies: 3
    Last Post: 08-19-2010, 01:35 PM

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