Page 1 of 2 12 LastLast
Results 1 to 15 of 16
  1. #1
    stryder09 is offline Advanced Beginner
    Windows XP Access 2007
    Join Date
    Feb 2011
    Posts
    85

    Code to create a query from a form

    Hey guys, I have a Process Change Form that has a bunch of yes/no check mark boxes on it. Is there a way depending which boxes are check marked for it to run a query and change another table to display only the valid information?

    I already have the table created that has the Names of the employees listed and their position. I also have a query table created that when I put in the position it will only display those employees of that position I want.

    What I am looking for though is depending which boxes are checked In the Process Change Form that it will give back only the employees needed on the Query table.

    ex. 5 yes/no check boxes for Driver, Packer, Operator, Maintenance and Supervisor. I have information that only the Driver, Packer and Supervisor needs to see, so only their yes/no boxes are checked. I need to have the Query table then print with only their names. This is a check off sheet that they sign off on saying they read the information.



    I am sure this is something that would need to be done in code.

    Any help would be appreciated?

    Brad

  2. #2
    rpeare is offline VIP
    Windows XP Access 2003
    Join Date
    Jul 2011
    Posts
    5,442
    Have you got an example database?

    Why would you create a table when you could use a query to pull out the information you want, or display the information you want?

    Record sources for forms/reports can be altered based on input from a form so I'm not sure where your use of tables comes in.

  3. #3
    June7's Avatar
    June7 is offline VIP
    Windows XP Access 2010 32bit
    Join Date
    May 2011
    Location
    The Great Land
    Posts
    53,624
    Table structure has a field for names and field for position? Try:

    Include expressions in query for the 5 positions and set Criteria for each as True (4 on different Or lines). Example for the driver:

    IIf([Position]="Driver" And Forms!formname!chkDriver=True),True,False)

    Or one long nested IIf for the 5 expressions and one criteria of True.
    How to attach file: http://www.accessforums.net/showthread.php?t=70301 To provide db: copy, remove confidential data, run compact & repair, zip w/Windows Compression.

  4. #4
    stryder09 is offline Advanced Beginner
    Windows XP Access 2007
    Join Date
    Feb 2011
    Posts
    85
    The table or query I wish to change isn't actually linked to this form. But I want the query to sort and display only the positions needed.

    I only have 4 fields Department, Employee, Position, Check Off. I don't have fields named Driver, Packer, Operator, Supervisor or Maintenance, they would be sorted under the field name position.

  5. #5
    June7's Avatar
    June7 is offline VIP
    Windows XP Access 2010 32bit
    Join Date
    May 2011
    Location
    The Great Land
    Posts
    53,624
    My suggestion does not require the query to be linked to the form, only refer to controls on the open form. I assumed you had one field for positions and my suggestion reflects that.

    What is the CheckOff field for?
    How to attach file: http://www.accessforums.net/showthread.php?t=70301 To provide db: copy, remove confidential data, run compact & repair, zip w/Windows Compression.

  6. #6
    stryder09 is offline Advanced Beginner
    Windows XP Access 2007
    Join Date
    Feb 2011
    Posts
    85
    The CheckOff field is actually a nothing field! This table is actually being generated from an excel table that gets updated regularly by our Training coordinator in the plant so is always current and that is just one of the fields that that table creates.

    How would I Nest the multiple IIF's? And am I putting this statement in the Criteria area of the query under Position?

  7. #7
    stryder09 is offline Advanced Beginner
    Windows XP Access 2007
    Join Date
    Feb 2011
    Posts
    85
    So I tried the following just to see if it works

    IIF(([Position]="Driver" AND [Reports]![Process Update]![Driver]=True,True,False)

    And I get the following Access error:

    This expression is typed incorrectly, or it is too complex to be evaluated. For example, a numeric expression may contain too many complicated elements. Try simplifying the expression by assigning parts of the expression to variables.

  8. #8
    stryder09 is offline Advanced Beginner
    Windows XP Access 2007
    Join Date
    Feb 2011
    Posts
    85
    Any help would be appreciated

  9. #9
    June7's Avatar
    June7 is offline VIP
    Windows XP Access 2010 32bit
    Join Date
    May 2011
    Location
    The Great Land
    Posts
    53,624
    There is an extra paren at beginning of the expression. Parens and quotes must be paired.

    Nested 2 IIF:
    IIF([Position]="Driver" AND [Reports]![Process Update]![Driver]=True,True, IIF([Position]="Packer" AND [Reports]![Process Update]![Packer]=True,True,False))
    How to attach file: http://www.accessforums.net/showthread.php?t=70301 To provide db: copy, remove confidential data, run compact & repair, zip w/Windows Compression.

  10. #10
    stryder09 is offline Advanced Beginner
    Windows XP Access 2007
    Join Date
    Feb 2011
    Posts
    85
    I can't get this statement to work

    IIF([Position]="Production Supervisor" AND [Forms]![PROCESS CHANGE]![Shift Supervisor]=True,True,False)

    But This one works for me.

    IIf(([Forms]![PROCESS CHANGE]![Shift Supervisor]=True),"Shift Supervisor")

    The Problem I have now is that the Shift Supervisor check box will also refer to the reserve Supervisors.

    I can get the statement to work this way

    IIf(([Forms]![PROCESS CHANGE]![Shift Supervisor]=True),"Shift Supervisor") Or IIf(([Forms]![PROCESS CHANGE]![Shift Supervisor]=True),"Relief Supervisor")

    BUt I want to write it this way and it won't work

    IIf(([Forms]![PROCESS CHANGE]![Shift Supervisor]=True),"Shift Supervisor" Or "Relief Supervisor")

    But it doesn't work?

  11. #11
    June7's Avatar
    June7 is offline VIP
    Windows XP Access 2010 32bit
    Join Date
    May 2011
    Location
    The Great Land
    Posts
    53,624
    I am confused. My suggested expression should work and yours should not. The expression goes in the Field row. This is constructing a calculated field. The Criteria row has True. Are you referencing the names of the checkboxes? Are these checkboxes bound to a field?

    See http://www.techonthenet.com/access/f...vanced/iif.php
    How to attach file: http://www.accessforums.net/showthread.php?t=70301 To provide db: copy, remove confidential data, run compact & repair, zip w/Windows Compression.

  12. #12
    stryder09 is offline Advanced Beginner
    Windows XP Access 2007
    Join Date
    Feb 2011
    Posts
    85
    The check box are bound to a different table yes. I am putting my calculation in the Criteria field of my Query Table.

  13. #13
    June7's Avatar
    June7 is offline VIP
    Windows XP Access 2010 32bit
    Join Date
    May 2011
    Location
    The Great Land
    Posts
    53,624
    You might follow my suggestion and see what happens.
    How to attach file: http://www.accessforums.net/showthread.php?t=70301 To provide db: copy, remove confidential data, run compact & repair, zip w/Windows Compression.

  14. #14
    stryder09 is offline Advanced Beginner
    Windows XP Access 2007
    Join Date
    Feb 2011
    Posts
    85
    It causes an error because the equation is looking for the answer in the Position field, which is where the equation is.

    Is there a way though in the criteria field to have the following equation and have it give back more than one answer.

    IIF(([Forms]![Process Change]![Shift Supervisor]=True), "Production Supervisor")

    I would like it to also return all the relief supervisors.

    IIF(([Forms]![Process Change]![Shift Supervisor]=True),"Production Supervisor" OR "Relief Supervisor")

    It doesn't work though, Is there another way to write it that it will let me bring back 2 or more positions?

  15. #15
    stryder09 is offline Advanced Beginner
    Windows XP Access 2007
    Join Date
    Feb 2011
    Posts
    85
    The error I get trying your equation is

    Circular reference caused by alias 'Position' in query definition's SELECT list.

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

Similar Threads

  1. Replies: 11
    Last Post: 09-27-2011, 07:19 AM
  2. vba code to create a dir
    By maxbre in forum Programming
    Replies: 5
    Last Post: 11-02-2010, 06:35 AM
  3. Using a query to create
    By DamnYankees in forum Queries
    Replies: 2
    Last Post: 10-08-2009, 07:38 PM
  4. Replies: 1
    Last Post: 03-02-2009, 11:54 AM
  5. how to create a macro or code to...
    By Eaglezinha in forum Access
    Replies: 1
    Last Post: 10-20-2008, 04:01 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