Results 1 to 3 of 3
  1. #1
    Join Date
    May 2010
    Posts
    2

    Question Unanswered: Need help with combo dropbox synchronization and copying data into row.

    I've got a simple database where I want to create a form where I add a Contact to a project, but I want to select the company first so I use synchronized combo boxes.

    Private Sub knopKlanten_AfterUpdate()
    Me.knopContact.RowSource = "SELECT Naam FROM" & _
    " Contactpersoon WHERE KlantenId = " & Me.knopKlanten & _
    " ORDER BY Naam"
    Me.knopContact = Me.knopContact.ItemData(0)
    End Sub

    Now I want to copy the ContactpersoonId (primary key from table Contactpersoon) into the table Project in the row ContactpersoonId as a foreign key.

    How can I do this?

  2. #2
    Join Date
    May 2010
    Posts
    601
    Quote Originally Posted by Marnix82 View Post
    I've got a simple database where I want to create a form where I add a Contact to a project, but I want to select the company first so I use synchronized combo boxes.

    Private Sub knopKlanten_AfterUpdate()
    Me.knopContact.RowSource = "SELECT Naam FROM" & _
    " Contactpersoon WHERE KlantenId = " & Me.knopKlanten & _
    " ORDER BY Naam"
    Me.knopContact = Me.knopContact.ItemData(0)
    End Sub

    Now I want to copy the ContactpersoonId (primary key from table Contactpersoon) into the table Project in the row ContactpersoonId as a foreign key.

    How can I do this?
    If I am understanding you correctly, you will need to include the ContactpersoonId field as a column in the combo cox. If you set the bound column be 1 so the column with the ContactpersoonId value gets returned by the combo box. Set the control source of the combo box to be the field in the form's record source when you want the data stored.

    Like this:
    Code:
    
    Private Sub knopKlanten_AfterUpdate()
    Me.knopContact.RowSource = "SELECT Naam, ContactpersoonId FROM" & _
                            " Contactpersoon WHERE KlantenId = " & Me.knopKlanten & _
                            " ORDER BY Naam"
    Me.knopContact = Me.knopContact.ItemData(0)
    End Sub
    Boyd Trimmell aka HiTechCoach HiTechCoach.com (free access stuff)
    Microsoft MVP - Access Expert
    BPM/Accounting Systems/Inventory Control/CRM
    Programming: Nine different ways to do it right, a thousand ways to do it wrong.
    Binary--it's as easy as 1-10-11

  3. #3
    Join Date
    May 2010
    Posts
    2
    Thanks for answering.

    The problem is that if I give any commands to the knopContact combobox I get an error because of the ItemData(0) command. So I can't set it so it will output the contactpersoon.contactpersoonId to project.contactpersoonId, or atleast I don't know how.
    Last edited by Marnix82; 05-17-10 at 12:35.

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts
  •