Results 1 to 3 of 3
  1. #1
    mitchmcc is offline Novice
    Windows XP Access 2007
    Join Date
    Nov 2011
    Location
    St. Petersburg, FL
    Posts
    19

    How to get key for drop-down list

    I have a relatively simple Access 2007 question, but as a newbie I am not sure how to get what I need. I should also note that I inherited an existing application that I am modifying.



    I have a simple "Add Employee" form that allows the employee's group to be selected via a drop-down list that is bound to the "Groups" table. So far, so good, and the drop-down works fine.

    Now, when the user presses the "Save" button, I can take the rest of the textboxes and use them for the insert into the Employees table, but at this point I now need to translate the Group name to be the Group ID, which is what is stored in the Employees table.

    Currently, I created a query called queryActiveGroups which is what the drop-down is bound to. It does NOT grab the Group ID, just the name and status.

    Is there a way to make the Group ID available to my VBA code if I include it in the query but mark it as "not shown" (or something like that)?

    I have used embedded selects in Oracle, where you could do the following (SQL pseudocode):

    insert into employees(name, group_id) values (lstEmpName, (select group_id from Groups where Group_Name = cboGroupName));

    Thanks,

    Mitch
    Last edited by mitchmcc; 11-28-2011 at 01:00 PM. Reason: clarification

  2. #2
    aytee111 is offline Competent At Times
    Windows 7 32bit Access 2010 32bit
    Join Date
    Nov 2011
    Location
    Nomad
    Posts
    3,936
    Grab the GroupID from the Groups table for your dropdown. Make it the first field. Set the column count to 2, the bound column to 1, and when setting the column widths set the first column to 0. Now any time you reference the dropdown you will be referencing the ID instead of the name - use xxx.column(1) to reference the name in VBA (numbering starts at 0 for the first column).

    It is also a good idea to bind your form directly to the Employees table instead of using SQL to insert the record afterwards. The GroupID can then be bound directly to the table.

  3. #3
    mitchmcc is offline Novice
    Windows XP Access 2007
    Join Date
    Nov 2011
    Location
    St. Petersburg, FL
    Posts
    19
    Thanks, aytee111... I think I understand now.

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

Similar Threads

  1. List box drop Issue
    By JonM in forum Access
    Replies: 1
    Last Post: 09-30-2011, 12:56 PM
  2. drop down list
    By slimjen in forum Access
    Replies: 6
    Last Post: 09-15-2011, 01:43 PM
  3. Replies: 4
    Last Post: 06-16-2011, 09:30 PM
  4. drop down list
    By tceicher in forum Access
    Replies: 5
    Last Post: 08-13-2009, 05:41 AM
  5. I can't create a drop-down list box
    By cpuser in forum Access
    Replies: 4
    Last Post: 02-18-2008, 10:11 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