Results 1 to 6 of 6
  1. #1
    annah is offline Novice
    Windows 7 64bit Access 2007
    Join Date
    Sep 2015
    Posts
    5

    How to use dlookup to filter a query instead of a table join

    I have a form where users are only allowed to see work assignments that belong to them. This is currently accomplished using a join between my employee table and my work assignment table, and a custom defined function that returns the logon id that is currently using the workstation to use as a criteria in the query. The employee table contains the employee's name and their logon id, and the work assignment table contains the employee's name.

    This creates a recordset that is not updateable and there are a few fields that I want the employees to be able to edit.

    I've used dlookup before to return values but not to use as a filter. I would like to be able to remove the join and just use dlookup as a criteria on the employee's name from the work assignment table but I'm struggling with syntax and I can't find an example on google.



    Thanks for your help!

  2. #2
    aytee111 is offline Competent At Times
    Windows 7 32bit Access 2013 32bit
    Join Date
    Nov 2011
    Location
    Nomad
    Posts
    3,936
    Use a filter on the form instead. The form's record source can be the work assignment table and OnOpen or OnLoad set the form's filter:

    Me.Filter="EmployeeName='" & DLookup("EmployeeName","EmployeeTable","LogonID='" & functionname & "'") & "'"
    Me.FilterOn=True

  3. #3
    annah is offline Novice
    Windows 7 64bit Access 2007
    Join Date
    Sep 2015
    Posts
    5
    Yeah that doesn't work because the user can just remove filter the form and then they will see everything else.

    I did figure out what to do though in case anyone has a similar question. Instead of trying to put the dlookup as a criteria under the employee's name, I set up a custom column in the query called "login" which returned the value of the dlookup. I then set the criteria for that column to be the custom function which returns the current user login id.

  4. #4
    aytee111 is offline Competent At Times
    Windows 7 32bit Access 2013 32bit
    Join Date
    Nov 2011
    Location
    Nomad
    Posts
    3,936
    Forms have a property - AllowFilters - which you can set to No.

  5. #5
    annah is offline Novice
    Windows 7 64bit Access 2007
    Join Date
    Sep 2015
    Posts
    5
    True, but then my users wouldn't be able to apply their own filters, which they need to be able to do.


    Quote Originally Posted by aytee111 View Post
    Forms have a property - AllowFilters - which you can set to No.

  6. #6
    John_G is offline VIP
    Windows 7 32bit Access 2010 32bit
    Join Date
    Oct 2011
    Location
    Ottawa, ON (area)
    Posts
    2,615
    This creates a recordset that is not updateable and there are a few fields that I want the employees to be able to edit.
    Try putting an index on the employee name field in both tables.

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

Similar Threads

  1. Replies: 3
    Last Post: 08-27-2016, 10:24 AM
  2. Replies: 6
    Last Post: 05-05-2014, 10:51 PM
  3. Replies: 3
    Last Post: 01-21-2014, 12:28 AM
  4. Query table join question
    By Nelson8 in forum Queries
    Replies: 1
    Last Post: 07-26-2013, 08:08 AM
  5. Adding records to a join table using a query
    By brharrii in forum Queries
    Replies: 5
    Last Post: 04-12-2013, 11:08 AM

Tags for this Thread

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