Results 1 to 13 of 13
  1. #1
    Dclassen89 is offline Novice
    Windows 7 64bit Access 2010 64bit
    Join Date
    Jan 2014
    Posts
    17

    Getting Form to Filter Records On Load


    I have a database with a simple login form"agent login" (calls to table for username and login, username is combobox) button that loads second form once logged in, I have another form which displays customer information for workers"agent homepage" Based on a customer information table(with a field for the assigned worker), I want to be able to setup the login form to load the other form with a filter, basically I want the form to display only customer records which will be assigned to specific workers. I am having trouble with the coding. I have a field in the second form with the workers login(for the filter). Is there any way to have my login form filter the records displayed on the second form based on the user which logs in? I am kinda stumped on this one. Any help would be greatly appreciated.

    I read tutorials stating I could add to the code in the button on my login form:
    DoCmd.OpenForm "AgentView" (something was added here to filter the results on load) I just dont know code at all.



    Edit: Even if I cant filter on load, what would be another effective method to display only customer records with a specific employee assigned to them in the table?

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

  3. #3
    Dclassen89 is offline Novice
    Windows 7 64bit Access 2010 64bit
    Join Date
    Jan 2014
    Posts
    17
    Im just confused what to use for the field and control name. Would the field be the text box on my form displaying the worker name and the control be the combobox for the username on the login form?
    This is what I came up with but not working
    DoCmd.OpenForm "AgentView", , , "Rep = " & Me.cboLogin

    Here is Full code

    Private Sub Login_Click()
    If Me.txtPwd = Me.cboLogin.Column(2) Then
    curUser = Me.cboLogin.Column(0)
    DoCmd.Close acForm, "LogonForm"
    DoCmd.OpenForm "AgentView", , , "Rep = '" & Me.cboLogin.Column(0) & "'"



    Else
    If ct < 4 Then

  4. #4
    Dclassen89 is offline Novice
    Windows 7 64bit Access 2010 64bit
    Join Date
    Jan 2014
    Posts
    17
    I figured it out, THANK YOU!!!! that was the last thing i needed to do to get this database to function

  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,652
    Happy to help and welcome to the site by the way!
    Paul (wino moderator)
    MS Access MVP 2007-2019
    www.BaldyWeb.com

  6. #6
    Dclassen89 is offline Novice
    Windows 7 64bit Access 2010 64bit
    Join Date
    Jan 2014
    Posts
    17
    Quote Originally Posted by pbaldy View Post
    Happy to help and welcome to the site by the way!
    Thank you sir. One more question on this code for the login button. Is it possible to make it filter for both records assigned to an employee AND customer records which have been assigned no employee? The employees are assigned in the customer table which the employee form is based upon.

  7. #7
    pbaldy's Avatar
    pbaldy is offline Who is John Galt?
    Windows XP Access 2007
    Join Date
    Feb 2010
    Location
    Nevada, USA
    Posts
    22,652
    Try

    DoCmd.OpenForm "AgentView", , , "Rep = '" & Me.cboLogin.Column(0) & "' OR Rep Is Null"
    Paul (wino moderator)
    MS Access MVP 2007-2019
    www.BaldyWeb.com

  8. #8
    Missinglinq's Avatar
    Missinglinq is offline VIP
    Windows 7 64bit Access 2007
    Join Date
    May 2012
    Location
    Richmond (Virginia, not North Yorkshire!)
    Posts
    3,018
    Quote Originally Posted by pbaldy View Post

    DoCmd.OpenForm "AgentView", , , "Rep = '" & Me.cboLogin.Column(0) & "' OR Rep Is Null"
    Just curious, but doesn't Is Null only work in SQL, not VBA?

    Linq ;0)>

  9. #9
    June7's Avatar
    June7 is offline VIP
    Windows 7 64bit Access 2010 32bit
    Join Date
    May 2011
    Location
    The Great Land
    Posts
    53,770
    The WHERE CONDITION argument follows SQL syntax - Is Null works. So does IsNull(Rep).
    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
    pbaldy's Avatar
    pbaldy is offline Who is John Galt?
    Windows XP Access 2007
    Join Date
    Feb 2010
    Location
    Nevada, USA
    Posts
    22,652
    Quote Originally Posted by Missinglinq View Post
    Just curious, but doesn't Is Null only work in SQL, not VBA?

    Linq ;0)>
    I'm surprised you didn't test it.
    Paul (wino moderator)
    MS Access MVP 2007-2019
    www.BaldyWeb.com

  11. #11
    Missinglinq's Avatar
    Missinglinq is offline VIP
    Windows 7 64bit Access 2007
    Join Date
    May 2012
    Location
    Richmond (Virginia, not North Yorkshire!)
    Posts
    3,018
    Quote Originally Posted by pbaldy View Post
    I'm surprised you didn't test it.
    Having a bad week...but as always, glad to to increase my personal Knowledge Base!

    Thanks, June7!

  12. #12
    Dclassen89 is offline Novice
    Windows 7 64bit Access 2010 64bit
    Join Date
    Jan 2014
    Posts
    17
    Quote Originally Posted by pbaldy View Post
    Try

    DoCmd.OpenForm "AgentView", , , "Rep = '" & Me.cboLogin.Column(0) & "' OR Rep Is Null"
    Exactly what I was looking for. You are really good at this stuff. Needless to say I will be sticking around this forum for advice as this project progresses. I am developing a database to allow agents in a call center to track customers and orders. My first real opportunity and you have helped tremendously with just this little code. Thanks!

  13. #13
    pbaldy's Avatar
    pbaldy is offline Who is John Galt?
    Windows XP Access 2007
    Join Date
    Feb 2010
    Location
    Nevada, USA
    Posts
    22,652
    Happy to help and welcome to the site by the way!
    Paul (wino moderator)
    MS Access MVP 2007-2019
    www.BaldyWeb.com

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

Similar Threads

  1. Replies: 8
    Last Post: 07-27-2012, 12:23 PM
  2. Filter a control on load
    By nick.h in forum Forms
    Replies: 1
    Last Post: 12-01-2011, 02:46 AM
  3. Replies: 3
    Last Post: 08-23-2011, 04:35 PM
  4. filter records to populate form on load
    By rivereridanus in forum Forms
    Replies: 3
    Last Post: 08-05-2011, 08:54 AM
  5. Form - Filter on load (if data exists)
    By dilbert in forum Forms
    Replies: 0
    Last Post: 08-13-2010, 11:39 AM

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