Page 1 of 4 1234 LastLast
Results 1 to 15 of 49
  1. #1
    cheyanne is offline Advanced Beginner
    Windows 7 64bit Access 2010 64bit
    Join Date
    Jan 2012
    Location
    Valencia, Spain
    Posts
    91

    Imported data has different ID

    I have two tables named tblClients and tblPets which I imported from another database.



    When I assigned it an autonumerical field ClientRef it had 1565 records on import.
    However the imported file also had a field ClientID, the original "ClientRef" field which had 1629 records.
    Clearly several records have been deleted over time.

    The problem that I have is that the linked ClientRef field, in tblPets table, has records which no
    longer match with the newly created Client ID from the imported table.

    When I deleted the ClientRef autonumber field, and used the ClientID field as an indexed field,
    the records matched, but it no longer generated autonumbers, which is essential.

    How can I remedy this situation so that the numbers in ClientID become the indexed field but
    also generates an automatic number starting at 1566 as the next record?

    Any advice would be greatly appreciated.

    Regards

    Cheyanne

  2. #2
    Missinglinq's Avatar
    Missinglinq is offline VIP
    Windows 7 64bit Access 2007
    Join Date
    May 2012
    Location
    Richmond (Virginia, not North Yorkshire!)
    Posts
    3,018
    This site gives a method of setting an Autonumber to a specified initital number. I think you can probably modify it to work for you:

    http://www.mvps.org/access/tables/tbl0005.htm

    Linq ;0)>
    The problem with making anything foolproof...is that fools are so darn ingenious!

    All posts/responses based on Access 2003/2007

  3. #3
    June7's Avatar
    June7 is online now VIP
    Windows XP Access 2010 32bit
    Join Date
    May 2011
    Location
    The Great Land
    Posts
    52,928
    Once table has records, can't change a field to an autonumber type. You can create another autonumber field in tblClients and let it number the records. If you are lucky the autonumber sequence will be the same as the existing ClientID and can just remove the original and rename the new (relationships, if established, will have to be removed and reset). If not, create another field in tblPets and update it to the new autonumber ID in an UPDATE query that joins the tables on the orginal pk/fk. After update, remove the relationship between the original pk/fk fields, delete old fields, rename new, and establish new relationship.
    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
    cheyanne is offline Advanced Beginner
    Windows 7 64bit Access 2010 64bit
    Join Date
    Jan 2012
    Location
    Valencia, Spain
    Posts
    91
    Hi

    Thanks for your collective efforts to date but the problem is more complex than I first thought.

    I have attached a screenshot, of a part of a database view of the Client file, showing where the problem lies.

    The two fields in question are named ID and ClientRef (this is the old IDRef from an imported Excel file which holds
    Client data from the old database.)

    Field ID is an autonumber field which shows 1565 records as opposed to the 1629 records in the ClientRef field.

    Over time users have clearly deleted some records, in the old database, and in reality it now contains 1565 Client records.

    If I needed only a Client File I could simply delete ClientRef and rename ID as ClientRef. However as this is a
    relational database the ClientRef numbers, in this database, also link to their pets in a table named tblPets.

    The consequences are that if I use field ID, as the Primary key, the pets are not linked to the correct Client.
    However, on the plus side the files auto increment. If I delete the ID field and use the Client Ref field, as the
    Primary key, then I suspect that the pets may be linked to the correct owner, but the field will not autoincrement.

    What I need to do is import all those 1565 records into a Client file (accepting that there will be around 64 "empty" records)
    Have them retain their old ClientRef i.e. the last record would be 1629 (with and somehow have this ClientRef field as
    an autonumber field which starts at 1630.

    Apologies if my original post was not explained as well as it could have been.

    I suspect that I shall have a similar problem in tblPets as well.

    As before any suggestions, or assistance will be gratefully received.

    Regards

    Cheyanne
    Attached Thumbnails Attached Thumbnails ClientList.JPG  

  5. #5
    recyan's Avatar
    recyan is offline Expert
    Windows 2K Access 2000
    Join Date
    Dec 2011
    Posts
    662
    Have you tried joining the new Clients Table ( with the new ClientID) with the Pets table with the join on ClientsRef (old), in a make table query & then try using the new table as the Pets table with the new ID (ClientID) in it as ClientsRef.

    Thanks

  6. #6
    cheyanne is offline Advanced Beginner
    Windows 7 64bit Access 2010 64bit
    Join Date
    Jan 2012
    Location
    Valencia, Spain
    Posts
    91
    Hi Recyan

    The short answer is no I haven't, but in honesty would not know how to do it and,
    more importantly do not understand what such a technique would do.

    Is there any chance you could outline exactly, and in detail what you think I need to do?

    Regards

    Cheyanne

  7. #7
    recyan's Avatar
    recyan is offline Expert
    Windows 2K Access 2000
    Join Date
    Dec 2011
    Posts
    662
    Just see if below gives some guidelines :

    Let us say, the original Clients Table imported in to access
    tblClients
    ClientRef - This is unique & theoretically the original PK
    .....

    After creating an Autonumber ID Field
    tblClients
    NewClientRef - PK - The Autonumber Field
    ClientRef - This is unique
    .....


    The Pets Table
    tblPets
    PetID - PK
    ClientRef
    .....

    Make a Make Table query :
    Code:
    SELECT 
        tblClients.NewClientRef, 
        tblClients.ClientRef, 
        tblPets.ClientRef, 
        tblPets.PetID,
        .......    
    INTO 
        tblClientsPets
    FROM 
        tblClients 
        INNER JOIN 
        tblPets 
        ON 
        tblClients.ClientRef = tblPets.ClientRef;
    Now perhaps, if everything is OK, you should be able to have a new one-many relationship between tblClients.NewClientRef and the New table tblClientsPets.NewClientRef.

    Discard the old table tblPets.

    Perhaps, there could be a simpler way.

    Thanks

  8. #8
    TG_W is offline Competent Performer
    Windows 7 64bit Access 2007
    Join Date
    May 2010
    Location
    Manvel, TX
    Posts
    299
    Just a quick suggestion (since this was posted in the "Forms" section), if you create new records from a form, why not set the default value for ClientRef to be =DMax("ClientRef","tblClients")+1 in the form? This should allow you to continue to "autonumber" the ClientRef field picking up where the old database left off.

  9. #9
    cheyanne is offline Advanced Beginner
    Windows 7 64bit Access 2010 64bit
    Join Date
    Jan 2012
    Location
    Valencia, Spain
    Posts
    91
    Hi Recyan

    Have tried as you suggested but I got an error message saying that the resultant table
    cannot have more than one autonumeric field.

    Stuck! but hey many thanks for the time you put into the reply - much appreciated.

    Regards

    Cheyanne
    Attached Thumbnails Attached Thumbnails ErrorMessage.JPG  

  10. #10
    cheyanne is offline Advanced Beginner
    Windows 7 64bit Access 2010 64bit
    Join Date
    Jan 2012
    Location
    Valencia, Spain
    Posts
    91
    Hi

    Many thanks for your suggestion which was much appreciated. I shall give that a go.

    Regards

    Cheyanne

  11. #11
    June7's Avatar
    June7 is online now VIP
    Windows XP Access 2010 32bit
    Join Date
    May 2011
    Location
    The Great Land
    Posts
    52,928
    A MAKE TABLE should not result in two autonumber fields. You don't need to copy the old ClientRef fields into the new table.

    There is also the method I suggested in post 3 but Recyan's might be better.
    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.

  12. #12
    cheyanne is offline Advanced Beginner
    Windows 7 64bit Access 2010 64bit
    Join Date
    Jan 2012
    Location
    Valencia, Spain
    Posts
    91
    Hi again

    I have just looked at your code again and wonder if I should have included all the other fields in the tblPets table
    under this

    tblClients.NewClientRef,
    tblClients.ClientRef,
    tblPets.ClientRef,
    tblPets.PetID,

    I have ended up with a table with just these four fields.

    Regards

    Cheyanne

  13. #13
    June7's Avatar
    June7 is online now VIP
    Windows XP Access 2010 32bit
    Join Date
    May 2011
    Location
    The Great Land
    Posts
    52,928
    Yes, Recyan's suggestion was an abbreviated example. Include all fields you want to replicate in the new table. Try with the wildcard:

    SELECT
    tblClients.NewClientRef,
    tblPets.*
    FROM
    ...
    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.

  14. #14
    cheyanne is offline Advanced Beginner
    Windows 7 64bit Access 2010 64bit
    Join Date
    Jan 2012
    Location
    Valencia, Spain
    Posts
    91
    Hi June 7

    Many thanks for your comment. I have now done that and the table has been made.
    The ClientRef field is now in synchronisation with the tblPets and the Pets now seem
    to link to their reepective owners.

    The only problem remaining is that of the inserting a new record. I need this to start at
    1630 and do not think I can introduce an autonumber field to a table that already has records in it.

    Off to consult the "books" again!

    My original version of this database functions perfectly but that was when I had introduced all the records. I do not relish having to introduce
    all the records that existed in their original database - hence my importing them. I am sure that I am not the first person to do this,
    but importing records seems to create more problems that it solves.

    Regards

    Cheyanne

  15. #15
    recyan's Avatar
    recyan is offline Expert
    Windows 2K Access 2000
    Join Date
    Dec 2011
    Posts
    662
    Quote Originally Posted by cheyanne View Post
    The only problem remaining is that of the inserting a new record. I need this to start at
    1630
    Are you telling that the next autonumber NewClientRefID should start at 1630.
    If yes,
    Why ?

    If the numbers in your first post is still relevant, then you have 1565 records.
    Hence the next autonumber ID for the NewClientRef would be 1566 ideally ( though not necessarily).
    Your old ClientRef is no longer relevant in the new tables.

    Thanks

Page 1 of 4 1234 LastLast
Please reply to this thread with any new information or opinions.

Similar Threads

  1. Replies: 7
    Last Post: 04-24-2012, 07:38 AM
  2. Replies: 3
    Last Post: 04-20-2012, 04:33 PM
  3. Imported data in table not shown in Forms
    By Zildjyn in forum Import/Export Data
    Replies: 9
    Last Post: 12-30-2011, 01:34 PM
  4. working with imported data
    By token_remedie in forum Queries
    Replies: 8
    Last Post: 09-21-2011, 05:52 PM
  5. Help with imported data
    By bubbasheeko in forum Queries
    Replies: 0
    Last Post: 01-12-2007, 07:12 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