Results 1 to 9 of 9
  1. #1
    iliast is offline Novice
    Windows 10 Access 2016
    Join Date
    Feb 2020
    Posts
    3

    Automatically update the contents of a table field

    How do I automatically update the contents of a table field, depending on what I'm importing into another field in the same table, using a compo-box?
    I have two tables. One is called "Materials" (IDMaterial, MaterialName, MaterialCode) and the other is table "Use" (IDUse, Date, IDMaterial, MateriaslCode).


    I want in Table Use, when I select Material from the compo-box (IDMaterial), to automatically appear in the next field, the corresponding MaterialCode, from the Materials table.
    I emphasize that this is what I want to do ONLY ON THE TABLE and that I will only work on. THERE WILL BE NO FORMS.
    Thank you.

  2. #2
    June7's Avatar
    June7 is offline VIP
    Windows 10 Access 2010 32bit
    Join Date
    May 2011
    Location
    The Great Land
    Posts
    53,771
    Why? This defeats a principle of relational database not to duplicate data. Save IDMaterial, pull MaterialsCode in a query that joins tables.

    Might be able to accomplish this with a Data Macro that executes an UPDATE action SQL. I don't use Data Macros.
    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
    iliast is offline Novice
    Windows 10 Access 2016
    Join Date
    Feb 2020
    Posts
    3
    Quote Originally Posted by June7 View Post
    Why? This defeats a principle of relational database not to duplicate data. Save IDMaterial, pull MaterialsCode in a query that joins tables.

    Might be able to accomplish this with a Data Macro that executes an UPDATE action SQL. I don't use Data Macros.
    My dear friend, what about to reveal specific only columns in the compo-box itself...? I don't mind to not have an extra field for "MaterialCode". It's enough for me selecting a Material from compo-box to see in the same field 2 columns. Name of the material, and code of the material. The result is the same for me. But... only working on the table. No forms.

  4. #4
    June7's Avatar
    June7 is offline VIP
    Windows 10 Access 2010 32bit
    Join Date
    May 2011
    Location
    The Great Land
    Posts
    53,771
    Why no form?

    Build combobox (lookup field) in table so MaterialCode is displayed for selection but IDMaterial is saved.
    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
    CJ_London is online now VIP
    Windows 10 Access 2010 32bit
    Join Date
    Mar 2015
    Posts
    11,933
    in a form, you would reference the relevant combo column with something like

    =fldName.column(2)

    but this is not functionality available in a table.

    So unless you are prepared to use a form, you are out of luck. You could look at using a data macro which might or might not work (I don't use them either) but that is only triggered when you leave the row, not when you update your combo column.

    only other suggestion is to concatenate your material name and code together as the displayed column.

    to clarify terminology

    depending on what I'm importing into another field in the same table, using a compo-box?
    you are not importing data, you are creating a link. Once that link is created, you can show the related data in a query.

  6. #6
    iliast is offline Novice
    Windows 10 Access 2016
    Join Date
    Feb 2020
    Posts
    3
    Quote Originally Posted by Ajax View Post
    in a form, you would reference the relevant combo column with something like

    =fldName.column(2)

    but this is not functionality available in a table.

    So unless you are prepared to use a form, you are out of luck. You could look at using a data macro which might or might not work (I don't use them either) but that is only triggered when you leave the row, not when you update your combo column.

    only other suggestion is to concatenate your material name and code together as the displayed column.

    to clarify terminology

    you are not importing data, you are creating a link. Once that link is created, you can show the related data in a query.
    Well, english isn't my native language, I'm sorry Ajax :-)
    The conclusion is that what I want is not done on a Table.
    Okay. Let's look at the Form option.

  7. #7
    June7's Avatar
    June7 is offline VIP
    Windows 10 Access 2010 32bit
    Join Date
    May 2011
    Location
    The Great Land
    Posts
    53,771
    I normally do not recommend lookup field in table but that would meet your requirement to display MaterialsCode without a form.
    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.

  8. #8
    CJ_London is online now VIP
    Windows 10 Access 2010 32bit
    Join Date
    Mar 2015
    Posts
    11,933
    @June - OP want's to display material code and name in two separate columns

    @iliast - did you consider my suggestion of concatenating code and name into one column?

    your rowsource would be something like

    Code:
    SELECT IDMaterial, MaterialCode & " - " & MaterialName FROM Materials ORDER BY MaterialCode

  9. #9
    June7's Avatar
    June7 is offline VIP
    Windows 10 Access 2010 32bit
    Join Date
    May 2011
    Location
    The Great Land
    Posts
    53,771
    Or:

    SELECT IDMaterial, MaterialName & " - " & MaterialCode FROM Materials ORDER BY MaterialName;

    So user types material name instead of material code but both values are displayed. Use whichever makes users happier.
    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.

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

Similar Threads

  1. Narrowing down field contents in table
    By Melrose in forum Access
    Replies: 1
    Last Post: 11-18-2015, 09:30 PM
  2. Replies: 2
    Last Post: 10-02-2012, 10:29 PM
  3. Replies: 4
    Last Post: 04-18-2011, 07:18 AM
  4. Replies: 0
    Last Post: 03-29-2011, 04:11 PM
  5. VBA to update field contents...Error 91
    By jpkeller55 in forum Access
    Replies: 9
    Last Post: 10-11-2010, 07:52 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