AfterUpdate - Fill in multiple fields

Ask a Question related to Microsoft Access, Design and Development.

  1. #1

    Default AfterUpdate - Fill in multiple fields

    My database serves as a complex contact manager, which no other
    commercial product emulates. My database has a Company Form for
    inputting company information. The Company form has an address
    subform.

    My objective involves selecting a previously entered address through a
    combo box field (addr1) and having AfterUpdate code automatically fill
    in the other address fields. My code draft returns an error upon
    activating the event. The combo box should allow new records for the
    input and to easily change the company addresses as well. The error
    message and code follow below.

    Run-time error '3331':

    Error Description: To make changes to this field, first save the
    record

    Private Sub cboAddr1_AfterUpdate()
    ' DOES NOT WORK
    Me![txtAddrID] = Me![cboAddr1].Column(0)
    Me![cboAddrName] = Me![cboAddr1].Column(1)
    Me![cboAddr1] = Me![cboAddr1].Column(2)
    Me![cboCity] = Me![cboAddr1].Column(3)
    Me![cboStateID] = Me![cboAddr1].Column(4)
    Me![txtPostalCode] = Me![cboAddr1].Column(5)
    Me![txtCountry] = Me![cboAddr1].Column(6)
    End Sub

    The following error occurs when selecting a control outside the
    sub-form.

    "The changes you requested to the table were not successful because
    they would create duplicate values in the index, primary key, or
    relationship. Change the data in the field or fields that contain
    duplicate data, remove the index, or redefine the index to permit
    duplicate entries and try again."

    This error message is straight-forward, yet I find myself at odds.
    The code changes the data in the relationship table where two fields,
    CompID and AddrID represent the index. The event is not creating a
    duplicate with this index. This point implies that either the index is
    not properly setup; or the subform has an inappropriate record source;
    or the code follows an incorrect syntax. Let me know if you could
    lead me in the right direction with this objective.

    TABLE
    tblComp trelCompAddr tblAddr

    FIELDS
    CompID CompID AddrName
    CompName AddrID Addr1
    CompTypeID Addr2 City
    Sector AddrTypeID State
    Phone PostalCode
    Phone2 Country
    Fax2
    Email

    Robert Neville Guest

  2. Similar Questions and Discussions

    1. overprint fill with multiple colors question
      I have some text in two different colors layed on top of a colored background. If I highlight all the text, I can't get overprint fill to stay on....
    2. PDF with fill-in fields saved in Standard 6 - open in any version of Reader?
      This is a format backwards compatibility question. If I save IRS forms with filled-in fields from Standard version 6.0, will someone be able to open...
    3. Search multiple keywords across multiple fields
      Hi, I'm about halfway through building a search engine using ASP, SQL and Access. As part of that search engine I need to search multiple...
    4. fill fields by value of another field
      One way is to use the After Update event of the combobox or listbox control, what ever you are using. This event is triggered each time the list...
    5. Fill in multiple fields with AfterUpdate
      Emilia, Sorry for the late response. My motherboard failed on me. The troubleshooting process took a greater portion of last week. Hardware...
  3. #2

    Default Re: AfterUpdate - Fill in multiple fields

    You have these two tables:
    - tblComp: one record for each company;
    - tblAddr: one record for each address.

    There is a many-to-many relationship between the, so have a 3rd table
    linking the two:
    - trelCompAddr: one record for each combination of company+address.

    If that's the case, trelCompAddr won't have all the address fields in it. It
    will have just these two fields:
    o CompID foreign key to tblComp.CompID
    o AddrID foreign key to tblAddr.AddrID.

    The interface would consist of a main form for Company, with a continuous
    subform. The subform has just a combo for selecting the addresses that are
    relevant to this company--one per row.

    I didn't understand why there was a copying of addresses going on.

    --
    Allen Browne - Microsoft MVP. Perth, Western Australia.
    Tips for Access users - [url]http://allenbrowne.com/tips.html[/url]
    Reply to the newsgroup. (Email address has spurious "_SpamTrap")

    "Robert Neville" <robert_neville@y@h0o.com> wrote in message
    news:lrf6hvgjqs5487vc2k43ch4pljq53ap6ej@4ax.com...
    > My database serves as a complex contact manager, which no other
    > commercial product emulates. My database has a Company Form for
    > inputting company information. The Company form has an address
    > subform.
    >
    > My objective involves selecting a previously entered address through a
    > combo box field (addr1) and having AfterUpdate code automatically fill
    > in the other address fields. My code draft returns an error upon
    > activating the event. The combo box should allow new records for the
    > input and to easily change the company addresses as well. The error
    > message and code follow below.
    >
    > Run-time error '3331':
    >
    > Error Description: To make changes to this field, first save the
    > record
    >
    > Private Sub cboAddr1_AfterUpdate()
    > ' DOES NOT WORK
    > Me![txtAddrID] = Me![cboAddr1].Column(0)
    > Me![cboAddrName] = Me![cboAddr1].Column(1)
    > Me![cboAddr1] = Me![cboAddr1].Column(2)
    > Me![cboCity] = Me![cboAddr1].Column(3)
    > Me![cboStateID] = Me![cboAddr1].Column(4)
    > Me![txtPostalCode] = Me![cboAddr1].Column(5)
    > Me![txtCountry] = Me![cboAddr1].Column(6)
    > End Sub
    >
    > The following error occurs when selecting a control outside the
    > sub-form.
    >
    > "The changes you requested to the table were not successful because
    > they would create duplicate values in the index, primary key, or
    > relationship. Change the data in the field or fields that contain
    > duplicate data, remove the index, or redefine the index to permit
    > duplicate entries and try again."
    >
    > This error message is straight-forward, yet I find myself at odds.
    > The code changes the data in the relationship table where two fields,
    > CompID and AddrID represent the index. The event is not creating a
    > duplicate with this index. This point implies that either the index is
    > not properly setup; or the subform has an inappropriate record source;
    > or the code follows an incorrect syntax. Let me know if you could
    > lead me in the right direction with this objective.
    >
    > TABLE
    > tblComp trelCompAddr tblAddr
    >
    > FIELDS
    > CompID CompID AddrName
    > CompName AddrID Addr1
    > CompTypeID Addr2 City
    > Sector AddrTypeID State
    > Phone PostalCode
    > Phone2 Country
    > Fax2
    > Email

    Allen Browne Guest

Posting Permissions

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

1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 65 66 67 68 69 70 71 72 73 74 75 76 77 78 79 80 81 82 83 84 85 86 87 88 89 90 91 92 93 94 95 96 97 98 99 100 101 102 103 104 105 106 107 108 109 110 111 112 113 114 115 116 117 118 119 120 121 122 123 124 125 126 127 128 129 130 131 132 133 134 135 136 137 138 139