Results 1 to 2 of 2
  1. #1
    summernightdrive is offline Novice
    Windows 7 32bit Access 2007
    Join Date
    May 2012
    Posts
    1

    Combo Box Trouble -Adds new record instead of refering to existing record

    Hey Guys and Gals. I am new to this forum and have a question that has been troubling me all day. I did plenty of searching and I couldn't find any answer, although it may be a simple one.



    So I have a combo box in a form that refers to a table that has a long list of companies. When I test out the combo box and pick one of the companies, it adds that company (with a new foreign key ID) as another record in the company table. So that company is now in the table twice. Is there any way to use the combo box to refer to a record that is already there instead of creating a new one off of your selection?

    I am sorry if this is a noob question... I just need it to do this so that the existing primary key for that company is carried over as a primary key for the relating table... not create a whole new record like it is. Thank you so much for your help!

  2. #2
    TheShabz is offline Court Jester
    Windows 7 64bit Access 2010 64bit
    Join Date
    Feb 2010
    Posts
    1,368
    You would have to use an IF statement in VBA to first see whether it exists in the table, and add to it if it doesnt. Here's some pseudoVBA to give you an idea. This would be on the AfterUpdate event of the combobox

    If DCount ("companyName", "tableName", "CompanyName = " & Me.ComboboxName) = 0 Then 'this means it doesn't exist
    'Code you have to add it in
    Else 'means it exists
    exit sub 'just exists and leaves it as is
    End If

    haven't tried this out but it makes sense logically.

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

Similar Threads

  1. Query adds record to table?!?
    By dantejazz in forum Queries
    Replies: 9
    Last Post: 03-11-2012, 08:58 PM
  2. Replies: 5
    Last Post: 03-02-2012, 08:58 PM
  3. Tab adds new record
    By xionhack in forum Forms
    Replies: 2
    Last Post: 06-14-2011, 01:17 AM
  4. Replies: 0
    Last Post: 02-25-2011, 09:40 AM
  5. Clicking on label adds new record?
    By swimmermx in forum Forms
    Replies: 1
    Last Post: 07-25-2010, 07:03 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