Results 1 to 7 of 7
  1. #1
    Sgt_Utz is offline Novice
    Windows 7 64bit Access 2013 64bit
    Join Date
    Aug 2017
    Posts
    25

    Trying to create a lookup field to dislay a dropdown list from another column in same table

    I am very new to Access so I apologize. I have a personnel table for all personnel within my Squadron (I'm in the Air Force). I want to create a lookup field with a dropdown to select the persons direct supervisor. This list needs to be all the people in the same table which it doesn't like. Does The Supervisor field have to be in a different table?



    I'd also like to filter out in the dropdown list anyone who is a lower rank than the person I'm trying to select the supervisor of. I created a table for ranks and assigned each rank a number. So basically if the person is a SSgt and is assigned number 5, then filter out all person except those with a rank of 1-5 (sometimes someone will be the supervisor of another person of the same rank).

  2. #2
    ranman256's Avatar
    ranman256 is offline VIP
    Windows Vista Access 2010 32bit
    Join Date
    Apr 2014
    Location
    Kentucky
    Posts
    9,522
    no, everything can be in 1 table
    PersonID
    FirstN
    LastN
    SuperID

    the superID would be the PersonID in the very same table. No need for extra tables.

    the Rank table in a query would feed the combo box (drop box)
    then it would filter the list:

    Code:
    sub cboBox_Afterupdate()
    If IsNull(cboBox) Then
      Me.FilterOn = False
    Else
      Me.Filter = "[RankCode]=" & cboBox 
      Me.FilterOn = True
    End If
    end sub
    or:
    "[RankCode] <= " & cboBox

  3. #3
    Sgt_Utz is offline Novice
    Windows 10 Access 2016
    Join Date
    Aug 2017
    Posts
    25
    I've been playing with it for a while and got it to get the list of everyone, but not sure how this filter code works. I attached a picture showing my tables and query and how it's setup. Where do I add this code?Click image for larger version. 

Name:	Supervisor.png 
Views:	23 
Size:	46.2 KB 
ID:	41882

  4. #4
    Sgt_Utz is offline Novice
    Windows 10 Access 2016
    Join Date
    Aug 2017
    Posts
    25
    *bumpity bumpity*

  5. #5
    Sgt_Utz is offline Novice
    Windows 10 Access 2016
    Join Date
    Aug 2017
    Posts
    25
    I'm sorry I'm a little confused about your code part. Where do I add this?

    Quote Originally Posted by ranman256 View Post
    no, everything can be in 1 table
    PersonID
    FirstN
    LastN
    SuperID

    the superID would be the PersonID in the very same table. No need for extra tables.

    the Rank table in a query would feed the combo box (drop box)
    then it would filter the list:

    Code:
    sub cboBox_Afterupdate()
    If IsNull(cboBox) Then
      Me.FilterOn = False
    Else
      Me.Filter = "[RankCode]=" & cboBox 
      Me.FilterOn = True
    End If
    end sub
    or:
    "[RankCode] <= " & cboBox

  6. #6
    Gicu's Avatar
    Gicu is offline VIP
    Windows 10 Access 2010 32bit
    Join Date
    Jul 2015
    Location
    Kelowna, BC, Canada
    Posts
    4,111
    You should avoid using lookup fields in tables (http://access.mvps.org/access/lookupfields.htm for more info) and use a combo box instead. Simply create a form based on your table, open it in design view and right click on the supervisor textbox and choose Change To and select combo box. For the new combo select column count as 2, Column Widths as 0";2", List Width as 2" RowSource Type as Table/Query and for the Row Source clcik the builder icon on the right (...) and build your Select statement:
    "Select ID,FullName:[LastName] &.....(like you already have it) FROM Personnel WHERE [Rank] > Forms![frmYourNewFormName]![Rank];".
    And finally in the Enter event of the supervisor combo box enter Me.cboSupervisor.Requery.

    Cheers,
    Vlad
    Vlad Cucinschi
    MS Access Developer
    http://forestbyte.com/

  7. #7
    Sgt_Utz is offline Novice
    Windows 10 Access 2016
    Join Date
    Aug 2017
    Posts
    25
    Thank you. I will play with this. Appreciate the wisdom!

    Quote Originally Posted by Gicu View Post
    You should avoid using lookup fields in tables (http://access.mvps.org/access/lookupfields.htm for more info) and use a combo box instead. Simply create a form based on your table, open it in design view and right click on the supervisor textbox and choose Change To and select combo box. For the new combo select column count as 2, Column Widths as 0";2", List Width as 2" RowSource Type as Table/Query and for the Row Source clcik the builder icon on the right (...) and build your Select statement:
    "Select ID,FullName:[LastName] &.....(like you already have it) FROM Personnel WHERE [Rank] > Forms![frmYourNewFormName]![Rank];".
    And finally in the Enter event of the supervisor combo box enter Me.cboSupervisor.Requery.

    Cheers,
    Vlad

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

Similar Threads

  1. Replies: 10
    Last Post: 03-16-2018, 08:26 AM
  2. How to narrow list in lookup dropdown?
    By Serhioromano in forum Access
    Replies: 8
    Last Post: 06-22-2016, 06:28 AM
  3. Replies: 2
    Last Post: 01-20-2016, 08:43 AM
  4. lookup dropdown list
    By LaughingBull in forum Access
    Replies: 9
    Last Post: 10-16-2015, 12:59 PM
  5. Replies: 2
    Last Post: 10-11-2011, 07:24 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