Page 1 of 2 12 LastLast
Results 1 to 15 of 20
  1. #1
    Hello1 is offline Advanced Beginner
    Windows 10 Access 2016
    Join Date
    May 2015
    Posts
    32

    Filtering forms

    Hello,

    I have a main form which contains few buttons which lead to other forms. The first button leads to another form which contains also few buttons to other forms, the first one leads to employees form, the other one to payoffs and so on.

    I want to add a combo box to the main form which will contain company names and based on the company I select I want the other forms to show only the employees which work for that particular company, payoffs of that company and so on, except some forms which have same data for all companies.

    Can you point me to some tutorials if this is even possible to make, and is this enuff information I gave or do I need to write it in more details?

    Thanks

  2. #2
    June7's Avatar
    June7 is offline VIP
    Windows 10 Access 2010 32bit
    Join Date
    May 2011
    Location
    The Great Land
    Posts
    53,771
    So what do you mean by 'leads to' - are you running DoCmd.OpenForm?

    Can use the WHERE CONDITION argument of DoCmd.OpenForm command to open form to a filtered recordset.
    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.

  3. #3
    davegri's Avatar
    davegri is offline Excess Access
    Windows 10 Access 2016
    Join Date
    May 2012
    Location
    Denver
    Posts
    3,741
    If you're using VBA, do this: For the forms that you want to restrict to employees of a particular company, the button would call the form with docmd.openform "frmTarget",,,,,,Openargs. The openargs would contain the companyId. When the target form opens, its On_Open event checks the openargs, and if present, filters the form for only that company. If openargs not present, then no filter and all data present.

  4. #4
    Hello1 is offline Advanced Beginner
    Windows 10 Access 2016
    Join Date
    May 2015
    Posts
    32
    The following example opens the frmMainEmployees form in Form view and displays only records that apply to the department chosen in the cboDept combo box. The displayed records can be edited, and new records can be added.Sample code provided by: Bill Jelen, MrExcel.com
    Code:
    VBCopy
    Private Sub cmdFilter_Click()
        DoCmd.OpenForm "frmMainEmployees", , , "DepartmentID=" & cboDept.Value EndSub
    Guess I could use this? Just how do I select the main form which contains the combobox? VBA is still foreign for me

    Code:
    VBCopy
    Private Sub cmdFilter_Click()
        DoCmd.OpenForm "frmEmployees", , , "CompanyID=" & "AllForms!frmMain" Me. cmb.cboCompanyID.Value EndSub
    Any close? lol
    And thanks for the help, would search forever

  5. #5
    June7's Avatar
    June7 is offline VIP
    Windows 10 Access 2010 32bit
    Join Date
    May 2011
    Location
    The Great Land
    Posts
    53,771
    The combobox is on frmMainEmployees? This code is behind one of the other forms?

    DoCmd.OpenForm "frmEmployees", , , "CompanyID=" & Forms!frmMainEmployees.cboCompanyID
    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
    davegri's Avatar
    davegri is offline Excess Access
    Windows 10 Access 2016
    Join Date
    May 2012
    Location
    Denver
    Posts
    3,741
    You haven't told us the name of your combobox, the name of the forms, the name of the button, the name of the field to filter on, or other details that makes specific advice possible.
    It might be best if you submit your DB for the relevant code to be added.

  7. #7
    Hello1 is offline Advanced Beginner
    Windows 10 Access 2016
    Join Date
    May 2015
    Posts
    32
    Its 2 times behind. frmMain -> frmOtherThings -> frmEmployees

    The combobox contains CompanyID (PK) and Name from the table Company which is linked to employees table to the CompanyID (FK)

    EDIT: Sorry I saw the last post after posting this one. I will try to write it more detailed now.

  8. #8
    Hello1 is offline Advanced Beginner
    Windows 10 Access 2016
    Join Date
    May 2015
    Posts
    32
    Ok, in the main form "frmMain" I have a combobox "cboCompanyID". It contains the "CompanyID" and "CompanyName" which is set to column count: 2 and bound colum: 1 so it shows the company name on the drop down list. Now, when I select a company from that list, I want the code to show me only the records of employees which work for that company.
    The employees are in the "frmEmployees" and to access that form I go from the "frmMain" to a form called "frmOtherStuff" and then on that form I click on the Employees button "cmdEmployees" and enter the "frmEmployees". In that form I have some employees info including the (FK) CompanyID.
    Hope I was a bit more clear this time

  9. #9
    davegri's Avatar
    davegri is offline Excess Access
    Windows 10 Access 2016
    Join Date
    May 2012
    Location
    Denver
    Posts
    3,741
    OK. The complication is that there is another form between the frmMain and frmEmployees, being frmOtherStuff. The company combobox is on frmMain. Then a button on frmMain loads frmOtherstuff, then a button on frmOtherStuff loads frmEmployees which needs to see the cboCompanyID combobox on frmMain.
    So the button on frmOtherStuff needs:
    DoCmd.OpenForm "frmEmployees", , , "CompanyID=" & Forms!frmMain.cboCompanyID
    pretty much as June7 said.

  10. #10
    Hello1 is offline Advanced Beginner
    Windows 10 Access 2016
    Join Date
    May 2015
    Posts
    32
    Now I get "enter parameter value" and under it the CompanyID. I have to add that I added the companyID in the frmEmployees additionally as I did the combobox on the main form. In the combobox row source: SELECT Company.CompanyID, Company.Name FROM Company;
    The companyID in the frmEmployees I added ith the option "Add existing fields"
    Do you happen to have a link for a small database example? :/

  11. #11
    davegri's Avatar
    davegri is offline Excess Access
    Windows 10 Access 2016
    Join Date
    May 2012
    Location
    Denver
    Posts
    3,741
    CompanyID must be in the recordsource for frmEmployees. If not present, then your table and relationship structure is wrong. This is getting complicated. Need your DB posted.

  12. #12
    Hello1 is offline Advanced Beginner
    Windows 10 Access 2016
    Join Date
    May 2015
    Posts
    32
    Its in another language, I made a small similar one. I get the same error, hopefully it can help. Thanks again
    Attached Files Attached Files

  13. #13
    davegri's Avatar
    davegri is offline Excess Access
    Windows 10 Access 2016
    Join Date
    May 2012
    Location
    Denver
    Posts
    3,741
    Didn't realize companyid was text. So the text field has to be delimited:
    Code:
    DoCmd.OpenForm "frmEmployees", , , "CompanyID='" & Forms!frmMain.cboCompanyID & "'"

  14. #14
    Hello1 is offline Advanced Beginner
    Windows 10 Access 2016
    Join Date
    May 2015
    Posts
    32
    Now it works, thanks!
    Maybe the moderator could change the thread title to a more fitting one, might be helpful to others.

  15. #15
    June7's Avatar
    June7 is offline VIP
    Windows 10 Access 2010 32bit
    Join Date
    May 2011
    Location
    The Great Land
    Posts
    53,771
    If you can still edit your original post, you should be able to change the title. Click 'Edit Post' then 'Go Advanced' below the Quick Reply edit window.
    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.

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

Similar Threads

  1. Dynamic Filtering on Forms
    By tonygg in forum Forms
    Replies: 3
    Last Post: 11-11-2015, 02:56 PM
  2. Filtering in Forms
    By djclntn in forum Forms
    Replies: 7
    Last Post: 03-21-2013, 05:30 PM
  3. Filtering Forms
    By Lupson2011 in forum Forms
    Replies: 1
    Last Post: 02-07-2012, 04:48 PM
  4. Filtering Forms
    By Iggsy in forum Forms
    Replies: 6
    Last Post: 11-23-2011, 01:01 AM
  5. Combo Box Filtering between Forms
    By andrew_ww in forum Access
    Replies: 3
    Last Post: 12-30-2009, 11:06 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