Results 1 to 6 of 6
  1. #1
    leungyen is offline Novice
    Windows 7 64bit Access 2010 32bit
    Join Date
    Jan 2015
    Posts
    9

    Lightbulb Query to create additional field in table

    Hi there, could you please help me to figure out how to create additional field from the table.




    1. I exported from text file to the access table

    It looks pretty much like this in the table

    ID Field1 Field2 Field3
    1 random random
    2 random random
    3 CustID 123A
    4 CName Mr.xyx
    5 random random random
    6 01/01/15 Order $150
    7 01/02/15 Order $200
    8 random random
    9 random random
    10 CustID 234B
    11 CName Mr.abc
    12 01/01/15 Order $125
    13 01/02/15 Order $225





















    2. What is the best way to get the result like the table below??
    CustID Field1 Field2 Field3
    123A 01/01/15 Order $150
    123A 01/02/15 Order $200
    234B 01/01/15 Order $125
    234B 01/02/15 Order $225








    Thanks in advance!!

    Y

  2. #2
    orange's Avatar
    orange is offline Moderator
    Windows XP Access 2003
    Join Date
    Sep 2009
    Location
    Ottawa, Ontario, Canada; West Palm Beach FL
    Posts
    16,848
    ??? I have no idea what you are trying to do.
    Your imported data seems to be of unknown format/structure.

    You need to structure your original text file into a meaningful, consistent list/format.

    I think you should post the original text file to show users what you are dealing with.

  3. #3
    June7's Avatar
    June7 is offline VIP
    Windows 7 64bit Access 2010 32bit
    Join Date
    May 2011
    Location
    The Great Land
    Posts
    53,626
    Is this a recurring process?

    Since the text file is not structured where each line represents a record, would require VBA code that opens and manipulates the text file as an object to import data into correct fields. A regular topic in forum. Search on keywords "read write text file".
    Last edited by June7; 05-21-2015 at 08:28 AM.
    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.

  4. #4
    leungyen is offline Novice
    Windows 7 64bit Access 2010 32bit
    Join Date
    Jan 2015
    Posts
    9
    Hi Orange, June, Thank you for your time to take a look at my problem.
    My apology that I did not make my question’s clear. Let me try again.
    This is the recurring process and has lots of data almost a million.
    I received text file and after imported into access it looks pretty much like the first table.
    I need the result to be like the second table, where each order, date, and amount purchased has the information of the customer (CustID)
    I just figured out how to get the result that I want. I have to do query over query but it works. This might be not the best way to do it. If someone can share with me how to do it more efficiently I will really appreciate it.


    Query1
    SELECT Tbl.ID, (SELECT Field2 FROM [tbl] WHERE ID=T.tmpID) AS CustID, T.Field1, T.Field2, T.Field3
    FROM (SELECT tbl.*, Nz((SELECT MAX(ID) FROM tbl AS tmp WHERE ID<[tbl].ID AND Field1="CustID"),[ID]) AS tmpID FROM tbl) AS T;

    Query2
    SELECT Query1.CustID, Query1.Field1, Query1.Field2, Query1.Field3
    FROM Query1
    WHERE (((Query1.Field2)="Order"));

  5. #5
    June7's Avatar
    June7 is offline VIP
    Windows 7 64bit Access 2010 32bit
    Join Date
    May 2011
    Location
    The Great Land
    Posts
    53,626
    But that leaves the data in table in improper structure. You have dealt with that in query and if you want to continue to, that is a choice.
    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.

  6. #6
    leungyen is offline Novice
    Windows 7 64bit Access 2010 32bit
    Join Date
    Jan 2015
    Posts
    9
    Hi June,

    I will take a look at your suggestion. I might need helps again letter. Thank you for your direction!

    Y

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

Similar Threads

  1. Do I need to create additional tables?
    By jamestford in forum Queries
    Replies: 3
    Last Post: 06-06-2014, 12:34 AM
  2. Replies: 7
    Last Post: 06-19-2013, 01:25 PM
  3. Additional field in a query
    By Berend Lindeman in forum Queries
    Replies: 2
    Last Post: 01-03-2012, 03:25 PM
  4. Replies: 11
    Last Post: 12-04-2010, 10:20 AM
  5. Replies: 1
    Last Post: 09-29-2010, 08:01 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