Results 1 to 15 of 15
  1. #1
    kris335 is offline Novice
    Windows XP Access 2007
    Join Date
    Jul 2011
    Posts
    23

    Formatting a concatenated field

    I have two auto sequential number fields that are formatted to be 3 digits long (such as 001 and 123). I have a third number field that combines those 2 numbers (i.e. 021-101). However, I cannot get the formatting to work in the 3rd field. It always reverts to 1-1 for the first record (or 2-2 for the 2nd), when I want it to say 001-001.

    I have it formatted in my property sheet as 000-000 and I also tried the Format function but couldn't get it to work correctly. The name of the combined field is Child Code, so my function was: Format([Child Code], "000-000") but I kept getting an "operand without an operator" error.



    Any help would be greatly appreciated!

  2. #2
    Robeen is offline VIP
    Windows XP Access 2010 32bit
    Join Date
    Mar 2011
    Location
    Tulsa, Oklahoma.
    Posts
    1,596
    Quick question:
    Are all these fields in a Table?

    Have you considered creating your concatenated field in a query instead?

    The reason I ask is that if this is in a table, you will be storing data that is already IN the table [your two number fields] into another table field thereby duplicating data.

  3. #3
    Robeen is offline VIP
    Windows XP Access 2010 32bit
    Join Date
    Mar 2011
    Location
    Tulsa, Oklahoma.
    Posts
    1,596
    If you want to try the Query then here's an example:

    Code:
     
    SELECT Table1.FirstNumber, Table1.SecondNumber, Format([FirstNumber],"000") + "-" + Format([SecondNumber],"000") AS JoinedNumber
    FROM Table1;
    Last edited by Robeen; 09-21-2011 at 08:45 AM. Reason: Typo.

  4. #4
    kris335 is offline Novice
    Windows XP Access 2007
    Join Date
    Jul 2011
    Posts
    23
    This is where it gets complicated. My first 3-digit number is called "Family-App ID" and it is from a table called "Parents". My second 3-digit number is called "Child ID" and it is from a table called "Child". So yes, my initial 3 digit codes are from a table.

    I have tried combining those fields in the table to display onto a form as well as just having an unbound text box on my form with my combined numbers. Either works but neither formats it properly.

  5. #5
    Robeen is offline VIP
    Windows XP Access 2010 32bit
    Join Date
    Mar 2011
    Location
    Tulsa, Oklahoma.
    Posts
    1,596
    Which Table are you trying to combine the numbers from the two different fields in??

    With the information you provided, you could have a query something like this [untested]:

    SELECT Parents.[Family-App ID], Child.[Child ID], Format(.[Family-App ID],"000") + "-" + Format([Child ID],"000") AS JoinedNumber
    FROM Parents, Child
    Where Parents.[JoinField] = Child.[JoinField];

    The above assumes that you have fields called 'JoinField' in both the tables.

    Let me know if this helps.

  6. #6
    kris335 is offline Novice
    Windows XP Access 2007
    Join Date
    Jul 2011
    Posts
    23
    Since the 2 joined numbers are from 2 different tables, which table would be the FROM table? And how do I get the "-" in there?

    Currently looks like this:
    SELECT Parent.[Family-App ID], Child.[Child ID], Format([Family-App ID],"000")+Format([Child ID],"000") AS JoinedNumber
    FROM Table1;

    Thanks for the help.

  7. #7
    kris335 is offline Novice
    Windows XP Access 2007
    Join Date
    Jul 2011
    Posts
    23
    Posted that last one before I saw your reply. Going to add what you suggested!

  8. #8
    kris335 is offline Novice
    Windows XP Access 2007
    Join Date
    Jul 2011
    Posts
    23
    Should I create the JoinField fields in both my tables?

  9. #9
    Robeen is offline VIP
    Windows XP Access 2010 32bit
    Join Date
    Mar 2011
    Location
    Tulsa, Oklahoma.
    Posts
    1,596
    There has to be a way to tell Access which field in Parent to join to which field in Child.

    If you want the [Family-App ID] and[Child ID] fields to be the joined fields - you can do this:

    Code:
    SELECT Parents.[Family-App ID], Child.[Child ID], Format(.[Family-App ID],"000") + "-" + Format([Child ID],"000") AS JoinedNumber
    FROM Parents, Child
    Where Parents.[Family-App ID] = Child.[Child ID];
    If you do - Access will look for a match in those fields between Parent & Child. So - the 001 in Parent will join to the 001 in Child.

    Let me know if that works.

  10. #10
    kris335 is offline Novice
    Windows XP Access 2007
    Join Date
    Jul 2011
    Posts
    23
    I have the query as my row source but when I go to open my form, it says it can't find a query named that and to check my record source. I can't find a property for "record" source.

  11. #11
    kris335 is offline Novice
    Windows XP Access 2007
    Join Date
    Jul 2011
    Posts
    23
    SELECT Parents.[Family-App ID], Child.[Child ID], Format(.[Family-App ID],"000") + "-" + Format([Child ID],"000") AS JoinedNumber
    FROM Parents, Child
    Where Parents.[Family-App ID] = Child.[Child ID];

    This is giving me a syntax error where it says to enclose the subquery in parenthesis. Which is the subquery?

  12. #12
    Robeen is offline VIP
    Windows XP Access 2010 32bit
    Join Date
    Mar 2011
    Location
    Tulsa, Oklahoma.
    Posts
    1,596
    So - you created the query - and it works?

    Then - you went into Form Properties and Changed where your Form is getting its data from? How did you do this?

    If you open your Form, Open the 'Property Sheet' and Click the 'Data' Tab - you should see a 'Record Source' Property that has a drop-down arrow from which you can select your query from the list.

  13. #13
    Robeen is offline VIP
    Windows XP Access 2010 32bit
    Join Date
    Mar 2011
    Location
    Tulsa, Oklahoma.
    Posts
    1,596
    you have a syntax error in there - my bad - sorry. There was a '.' in the 'Format(.[Family-App ID],"000")

    Try this:

    Code:
     
    SELECT Parents.[Family-App ID], Child.[Child ID], Format([Family-App ID],"000") + "-" + Format([Child ID],"000") AS JoinedNumber
    FROM Parents, Child
    Where Parents.[Family-App ID] = Child.[Child ID];

  14. #14
    kris335 is offline Novice
    Windows XP Access 2007
    Join Date
    Jul 2011
    Posts
    23
    When I make the record source the query, it messes up the rest of the form. Can I make the query the source for just the "Child Code" field?

  15. #15
    Robeen is offline VIP
    Windows XP Access 2010 32bit
    Join Date
    Mar 2011
    Location
    Tulsa, Oklahoma.
    Posts
    1,596
    How is it messing up the rest of the Form?

    It IS possible to get the value for 'Child Code' from the query - but it will involve writing VBA code.

    Is your Form a very complicated one? If not - you might just re-build it using the query as the data source.

    OR - try this:

    Make sure that your query has all the same fields that your Form has.
    Then -
    For each field on your Form -
    Select the field -
    Go to its Property Sheet - Data tab -
    Make sure the Control Source is one of the available fields from the drop-down list.

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

Similar Threads

  1. Replies: 2
    Last Post: 08-18-2011, 11:40 AM
  2. Formatting a Concatenated Field
    By CoachBarker in forum Queries
    Replies: 2
    Last Post: 09-23-2010, 09:12 AM
  3. Formatting a Calculated Field
    By e_lady333 in forum Queries
    Replies: 0
    Last Post: 03-17-2010, 06:11 PM
  4. Sum values in concatenated fields
    By jdrubins in forum Reports
    Replies: 4
    Last Post: 09-01-2009, 07:20 AM
  5. Need Help Formatting a field.
    By marshallgrads in forum Access
    Replies: 4
    Last Post: 12-06-2007, 03:44 AM

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