Results 1 to 6 of 6
  1. #1
    tareyj8569 is offline Advanced Beginner
    Windows Vista Access 2007
    Join Date
    Aug 2009
    Posts
    43

    Using a combo box from main form to filter in a function

    I have the below code, which is working (thanks to help from here) but I have a different question.



    =Sum(IIf([Pass or Fail]="Pass" And [Pay Period]="02" And [Location]="Purple",1,0))/IIf(Sum(IIf([Pay Period]="02" And [Location]="Purple",1,0)) = 0, 1, Sum(IIf([Pay Period]="02" And [Location]="Purple",1,0)))

    For [Pay Period] ="02" is there a way to make it filter by a combo box from the Mainform? This code is on a Subform the combo box is on a Mainform

    Forms![Overview_]![Combo35] <the path for the combo box.

    I tried inserting it where the 02 was but it just returns 0 and if I remove the "" it will error the whole thing out. Same if I try to just remove the [Pay Period]="02" and replace it fully it errors out.

    Maybe I am asking for too much of access I am not sure but I do appreciate you taking the time to read and help.

  2. #2
    tareyj8569 is offline Advanced Beginner
    Windows Vista Access 2007
    Join Date
    Aug 2009
    Posts
    43
    To try and simplify without so much there I am just trying to as =Sum(IIf([Pass or Fail]="Pass" And [Pay Period]="02" And [Location]="Purple",1,0)) and leaving the rest off to see if I can just get it to work like this.

    =Sum(IIf([Pass or Fail]="Pass" And [Pay Period]=Forms![Overview_]![Combo35] And [Location]="Purple",1,0))
    =Sum(IIf([Pass or Fail]="Pass" And [Pay Period]="Forms![Overview_]![Combo35]" And [Location]="Purple",1,0))
    =Sum(IIf([Pass or Fail]="Pass" And Forms![Overview_]![Combo35] And [Location]="Purple",1,0))
    =Sum(IIf([Pass or Fail]="Pass" And [Forms!][Overview_]![Combo35] And [Location]="Purple",1,0))

    None of the above worked. - wanted to show what I have tried

  3. #3
    JamesDeckert is offline Competent Performer
    Windows 7 64bit Access 2013
    Join Date
    Jul 2015
    Location
    Salina, KS
    Posts
    262
    try referencing the main form from the subform like this
    me.parent![Combo35]


  4. #4
    tareyj8569 is offline Advanced Beginner
    Windows Vista Access 2007
    Join Date
    Aug 2009
    Posts
    43
    Same thing=/ just 0 if I put in between " " and errors everywhere if I leave off " "

  5. #5
    JamesDeckert is offline Competent Performer
    Windows 7 64bit Access 2013
    Join Date
    Jul 2015
    Location
    Salina, KS
    Posts
    262
    do not put between quotes. show the line that you're getting an error on.
    if you leave out the "And me.parent![Combo35]", then you don't get an error, but putting it in gives you an error?
    what is contained in the combo box?
    maybe you need a cbool(
    me.parent![Combo35]) to convert it to boolean

  6. #6
    tareyj8569 is offline Advanced Beginner
    Windows Vista Access 2007
    Join Date
    Aug 2009
    Posts
    43
    I am going to mark this as solved.
    I ended up putting the requirement in the query and took it out of the function.
    Thanks for your time and help

Please reply to this thread with any new information or opinions.

Similar Threads

  1. Replies: 2
    Last Post: 02-25-2013, 10:47 AM
  2. Replies: 3
    Last Post: 06-02-2012, 07:39 PM
  3. filter main form base on subform data
    By ss3373 in forum Access
    Replies: 7
    Last Post: 06-24-2011, 09:21 PM
  4. Replies: 5
    Last Post: 01-02-2011, 10:09 AM
  5. Replies: 0
    Last Post: 08-17-2008, 12:19 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