Results 1 to 5 of 5
  1. #1
    Join Date
    Nov 2003
    Posts
    66

    Unanswered: Combining multiple field values into one field

    Hi all,

    I've a data entry form that includes fields 'Surname', 'Given Name', 'Middle Initial', and 'Differentiator'.

    I need to capture the values the user enters into these fields, and populate another hidden text field (on the same frickin form) with a string that combines all four values, ie "SnameGnameMInitDiff". This string then needs to go back into the same underlying table as all the rest of the entered data, and (hopefully) I can use it on later 'edit' forms for finding records, and for generating reports etc.

    I don't want to use dlookup for the new 'string' field seeing as I need to get it's value back into the table.
    Any ideas on how I do this?

    Cheers,
    D

  2. #2
    Join Date
    Jul 2002
    Location
    Island of Dots
    Posts
    316
    Call your hidden field 'txtCombinedField' and set its ControlSource to the appropriate field in your table. In your code, use:

    Code:
    txtCombinedField = _
    txtSurname & txtGivenName & txtMiddleInitial & txtDifferentiator
    Save your record after that to update the record in the table. Note that anything with the prefix 'txt' refers to a control on your form, and not necessarily a field in your table, so you need to name your text boxes on your form accordingly.
    Last edited by bcass; 11-26-03 at 18:04.

  3. #3
    Join Date
    Nov 2003
    Posts
    66
    Cheers for the reply, bcass.
    I'm a noob to Access/VB, so please bear with me...!

    2 dumb questions.....

    1) You say 'In your code, use....' - Where do I put the code? If the control source for the field relates to it's corresponding field in the table, I can't put the code there, so do I put it on an event? ie - 'Got Focus' for the new 'string' field?

    b) 'Save your record after that to update the record in the table' - Does this mean this particular 'string' field on the record isn't populated untill I run some sort of query AFTER the record is saved with the rest of its data?

    D

  4. #4
    Join Date
    Jul 2002
    Location
    Island of Dots
    Posts
    316
    You could create a button (call it a Save button) that the user should press when they want to perform the action you outline, which also saves the record (with the updated data in your hidden field). Create a button on your form, and assign the following code to its OnClick Event:

    Code:
    txtCombinedField = _
    txtSurname & txtGivenName & txtMiddleInitial & txtDifferentiator
    DoCmd.RunCommand acCmdSaveRecord
    This concatenates your fields into the hidden field, and then saves the record.

  5. #5
    Join Date
    Nov 2003
    Posts
    66
    Worked great!
    Cheers, bcass.

    D

Posting Permissions

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