Results 1 to 7 of 7
  1. #1
    MFS is offline Competent Performer
    Windows 7 32bit Access 2010 32bit
    Join Date
    Mar 2009
    Location
    Ohio
    Posts
    235

    Automatically Populate Text Box with Primary Key Value

    Here is what I am trying to do, I'm hoping that it is simple, but for some reason I cannot figure it out.



    The table I am working with has two fields.
    One for the Automatic Number, Primary Key, for each record. For this thread I will call it Container_Id
    The other field I have named as Container_Size.

    On my form, I have a Combo Box that shows all records of my container sizes. What I need is for a text box to automatically show the value of the Primary Key for whichever container size I choose.

    Can this be accomplished?

    Speck

  2. #2
    June7's Avatar
    June7 is offline VIP
    Windows 7 64bit Access 2010 32bit
    Join Date
    May 2011
    Location
    The Great Land
    Posts
    53,770
    Why? Autonumber primary keys generally can be kept hidden because they seldom have any meaning to users.

    However, what is actually being saved from the combobox? Are you saving the ID or the size? If you are saving the ID then can simply set a textbox ControlSource to the field. Lock the textbox if you don't want users to edit. If you are saving the size then the ID serves no purpose.
    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
    MFS is offline Competent Performer
    Windows 7 32bit Access 2010 32bit
    Join Date
    Mar 2009
    Location
    Ohio
    Posts
    235
    June7,

    I reference the Primary Key number within a Programmable Logic Controller, PLC. (Much easier to send whole numbers to an integer file than a physical dimension.)

    My combo box shows container sizes, when an operator chooses a 20x20 container I need a text box to show the primary key.
    How can this be performed?

  4. #4
    June7's Avatar
    June7 is offline VIP
    Windows 7 64bit Access 2010 32bit
    Join Date
    May 2011
    Location
    The Great Land
    Posts
    53,770
    Didn't really answer my question. Regardless of what the combobox shows the user, is the combobox saving the ID or the size? What is the combobox RowSource?
    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.

  5. #5
    MFS is offline Competent Performer
    Windows 7 32bit Access 2010 32bit
    Join Date
    Mar 2009
    Location
    Ohio
    Posts
    235
    Saves Container_Size

  6. #6
    June7's Avatar
    June7 is offline VIP
    Windows 7 64bit Access 2010 32bit
    Join Date
    May 2011
    Location
    The Great Land
    Posts
    53,770
    So the ID is not used as PK/FK in your db. It has some other purpose. Since you save the Size text info, that is the PK. To prevent duplicate Size entries in the Sizes table, the Size field should be set as PK or at least an index (no duplicates).

    Recommend you set the combobox as multi-column:

    RowSource: SELECT Size, ID FROM tblSizes ORDER BY Size;
    ColumnCount: 2
    BoundColumn: 1
    ColumnWidths: 1";0"

    Then expression in textbox can reference the ID column by index - index begins with 0:

    =[cboSizes].[Column](1)
    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.

  7. #7
    MFS is offline Competent Performer
    Windows 7 32bit Access 2010 32bit
    Join Date
    Mar 2009
    Location
    Ohio
    Posts
    235
    Thank You again for your help June7

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

Similar Threads

  1. Replies: 3
    Last Post: 08-08-2015, 10:59 AM
  2. Replies: 6
    Last Post: 07-09-2015, 06:04 AM
  3. Replies: 3
    Last Post: 01-15-2014, 10:39 PM
  4. Get last ID of primary key automatically generated
    By California2013 in forum Access
    Replies: 1
    Last Post: 09-12-2013, 05:57 AM
  5. Replies: 2
    Last Post: 07-28-2011, 09:20 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