Results 1 to 4 of 4
  1. #1
    mkling is offline Novice
    Windows 7 32bit Access 2010 32bit
    Join Date
    May 2012
    Posts
    27

    Update Existing Record in One Table with Key from Another Table

    I have an Event Table with an Index Key name 'Event ID' I have a sub key name 'Vendor ID' which I link to a Vendor table. In the Event form I have a combo box which displays a list of vendors from a prepopulated table and form named "Vendors". When I select a vendor, I want to update the Event table's 'Vendor ID' with the Index Key called [Vendor ID] from the Vendor table.



    In the event form, I have a combo box named [ECompany Combo]. The rowsource is SELECT Vendor.[Company/Organization], Vendor.[Vendor ID] FROM Vendor;

    This is the code I can't get to work:

    Code:
    Private Sub ECompany_Combo_AfterUpdate()
    [event].[vendor id].value = [forms]![event].[ecompany combo].column(1)
    End Sub
    Thanks in advance

  2. #2
    ketbdnetbp is offline Competent Performer
    Windows 7 32bit Access 2003
    Join Date
    Mar 2011
    Location
    Midwest
    Posts
    254
    Mkling - Assuming the Event table is the recordsource for the event form and [vendor ID] is a control on the Event Form, try

    Me![vendor id] = [forms]![event]![ecompany combo].column(1)

    Hope this helps,

    Jim
    Last edited by ketbdnetbp; 05-22-2012 at 03:57 PM. Reason: made assumptions about the form without confirmation

  3. #3
    mkling is offline Novice
    Windows 7 32bit Access 2010 32bit
    Join Date
    May 2012
    Posts
    27
    Thanks Jim. In order to get it to "almost" work, I added the event.[vendor id] to the form and made it not visable. When I say it almost worked, what happened was it inserted a new record into the event table.

    What I would like to do is update the record I am currently working on.

    I created several queries to do this to other fields. One is Point of Contact Phone1 [POC Phone 1]. The SQL is:
    Code:
    UPDATE Event SET Event.[POC Phone 1] = [Forms]![Event].[QPOC Phone 1]
    WHERE (((Event.[Event Name])=forms!Event![QEvent Name Combo]) And ((Event.[Event Date])=Forms!Event![QEvent Date Combo]));
    Here the table is updated when I key in information. My challenge is updating the current record from another table. I use the event name and date of the event in my query to ensure i update the record I want.

    Can I create a query which uses the [forms]![event].[ecompany combo].column(1) and the "WHERE" criteria?

  4. #4
    mkling is offline Novice
    Windows 7 32bit Access 2010 32bit
    Join Date
    May 2012
    Posts
    27
    I think I got it solved. Here is my code:

    Code:
    Private Sub ECompany_Combo_AfterUpdate()
    Me.Vendor_ID = Me.ECompany_Combo.Column(1)
    DoCmd.SetWarnings False
    DoCmd.OpenQuery "Update Event with Vendor ID Query", acViewNormal
    DoCmd.SetWarnings True
    Here is my query:

    Code:
    UPDATE Event SET Event.[Vendor ID] = [Forms]![Event]![Vendor ID]
    WHERE (((Event.[Event Name])=[forms]![Event]![QEvent Name Combo]) AND ((Event.[Event Date])=[Forms]![Event]![QEvent Date Combo]));
    I had to have [event].[vendor id] on the form like you suggested. I hid it and it seems to be working.

    Thank you

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

Similar Threads

  1. Replies: 11
    Last Post: 07-24-2012, 07:50 PM
  2. Total table from existing table from
    By HectorH in forum Access
    Replies: 2
    Last Post: 07-26-2011, 02:41 PM
  3. Replies: 7
    Last Post: 04-15-2011, 08:46 AM
  4. Replies: 0
    Last Post: 02-25-2011, 09:40 AM
  5. Using VBA create a new table from an existing table
    By KramerJ in forum Programming
    Replies: 0
    Last Post: 03-25-2009, 04:07 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