Results 1 to 9 of 9
  1. #1
    Famfeld is offline Novice
    Windows 10 Office 365
    Join Date
    Apr 2021
    Posts
    9

    How to have a field autofill with values from previous fields.

    I am new to this forum and not very experienced with Access, so please be patient with me. I would like to have 4 fields populate the 5th one. Here is what I mean:



    Field 1: Name (text)
    Field 2: City (text)
    Field 3: Number 1 to 10 (number)
    Field 4: Car color (text)

    so these four fields are entered, but a fifth field will then be created automatically and formatted a certain way. I can have the number be the primary key if that is important.

    Here is an example:

    I enter, Bob
    Brooklyn
    20
    Red into the four fields in one record, then the fifth field autopopulates to Bob_Brooklyn_20_Red


    I can think of how to do this with a Python script relatively easily, and I imagine it can be done.


    Any help greatly appreciated.

    Famfeld

  2. #2
    kd2017 is offline Well, I tried at least.
    Windows 10 Access 2016
    Join Date
    Jul 2017
    Posts
    1,165
    Does it have to be a field? Can it just be generated at runtime using a query using string concatenation?

    SELECT [Name] & "_" & [City] & "_" & [Number] & "_" & [Car color] FROM [MyTable];

    *Note: Name and Number are reserved words, don't use them as field names: http://allenbrowne.com/AppIssueBadWord.html

  3. #3
    Bulzie is offline VIP
    Windows 7 64bit Access 2007
    Join Date
    Nov 2015
    Posts
    1,511
    Or if you want it on the screen, you can put it in the AfterUpdate event on each of the first 4 fields, that way if they go back and change any values it will update Field5.

    Me.Field5 = me.Field1 & "_" & me.Field2 & "_" & me.Field3 & "_" & me.Field4

  4. #4
    Famfeld is offline Novice
    Windows 10 Office 365
    Join Date
    Apr 2021
    Posts
    9
    This is what I want to do.

    Where do I write this string?

    Thank you

  5. #5
    Minty is offline VIP
    Windows 10 Office 365
    Join Date
    Sep 2017
    Location
    UK - Wiltshire
    Posts
    3,144
    I agree with kd2017's post - Generally speaking, what you want for field 5 is the result of a calculation.

    As a rule in a database you don't store anything that can be calculated, simply because if anything changes in the underlying data, you have to capture that change somehow and update you stored value.
    There are some exceptions, such as maybe invoice line tax values that have to be stored due to legal & auditing considerations, but most of the time in a database it's best avoided.
    DLookup Syntax and others http://access.mvps.org/access/general/gen0018.htm
    Please use the star below the post to say thanks if we have helped !
    ↓↓ It's down here ↓↓

  6. #6
    Bulzie is offline VIP
    Windows 7 64bit Access 2007
    Join Date
    Nov 2015
    Posts
    1,511
    Consider what those guys are suggesting on if you need to store it or not. But if you do want to have it save in Field5, then go to design on form, click properties on each field and go Events and AfterUpdate and put that code(again need to do that for each field). Other way is on the BeforeUpdate event on the form itself, you can add that code and it should update Field5 also when you save the record.

  7. #7
    Famfeld is offline Novice
    Windows 10 Office 365
    Join Date
    Apr 2021
    Posts
    9

    I agree

    I understand that. How can I get it displayed? Using a report? I think I understand this but may just be too inexperienced to make this happen.

    Thanks for the help.




    Quote Originally Posted by Minty View Post
    I agree with kd2017's post - Generally speaking, what you want for field 5 is the result of a calculation.

    As a rule in a database you don't store anything that can be calculated, simply because if anything changes in the underlying data, you have to capture that change somehow and update you stored value.
    There are some exceptions, such as maybe invoice line tax values that have to be stored due to legal & auditing considerations, but most of the time in a database it's best avoided.

  8. #8
    June7's Avatar
    June7 is online now VIP
    Windows 10 Access 2010 32bit
    Join Date
    May 2011
    Location
    The Great Land
    Posts
    53,644
    Why not simple expression in query or textbox:

    Field1 & "_" & Field2 & "_" & Field3 & "_" & Field4
    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.

  9. #9
    Blings's Avatar
    Blings is offline Competent Performer
    Windows 10 Office 365
    Join Date
    May 2020
    Location
    London, UK
    Posts
    125
    Quote Originally Posted by Famfeld View Post
    I understand that. How can I get it displayed? Using a report? I think I understand this but may just be too inexperienced to make this happen.

    Thanks for the help.
    Give field 5 an alias in your query for that specific report which will concatenate your data i.e.

    Code:
    Field5: [Field1] & "_" & [Field2] & "_" & [Field3] & "_" & [Field4]
    See what I use on my form where I use DDCP as an ALIAS which stands for Delivery Detail Contact Person. The [DCP] is the Delivery Contact Person field and the [DCN] is Delivery Contact Number where I concatenate as one field known as DDCP. So on the form you can call it by using an unbound text box by using: =([Field5])

    Code:
    DDCP: "Contact:" & " " & [DCP] & ", " & [DCN]

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

Similar Threads

  1. Replies: 12
    Last Post: 11-15-2017, 06:58 PM
  2. Autofill field from previous fields entered
    By jucooper1 in forum Forms
    Replies: 17
    Last Post: 12-31-2016, 11:29 AM
  3. Replies: 1
    Last Post: 02-14-2015, 02:29 AM
  4. Replies: 7
    Last Post: 02-10-2012, 08:08 PM
  5. Autofill from Previous Field
    By Dan Kenton in forum Forms
    Replies: 1
    Last Post: 02-16-2011, 11:15 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