mgmercurio
Member
- Local time
- Today, 00:39
- Joined
- Jan 18, 2021
- Messages
- 55
Hello all ! First I want to say thank you in advance from all the experts here. I am a novice Access user and don't really know what I am doing...but can stumble my way through...
Anyway, I have two very large tables in my database:
tbl_Accounts
AccountID (PK)
AccountName (Short Text) joined in a 1 to many (left to right) relationship with AccountName in tbl_Contacts
AccountPhone (ShortText)
AccountFax(Short Text)
AccountBillingStreet1 (Short Text)
AccountBillingStreet2 (Short Text)
AccountCity (Short Text)
AccountState (Short Text)
AccountZipcode (Short Text)
tbl_Contacts
AccountContactID (PK) Autonumber
AccountID (FK) number
AccountName (shorttext) joined in a 1 to many relationship with AccountName in tbl_Accounts
FirstName (shorttext)
LastName (shorttext)
OfficePhone (shorttext)
MobilePhone (shorttext)
Email (shorttext)
I have already imported the data into both tables from spreadsheets and tbl_account table holds 2200 records. tbl_Contacts holds 8800 records
The reason the contacts table hold more records is because, for many of the accounts; there are many contacts specific to that account. In some cases, I could have a 100 contacts for one specific account. Two more pieces of info before I ask my question...
1. In each of these tables, the AccountName field holds the exact same name. However, in the Contacts table, there is multiple records with the same accountname. (due to some accounts have multiple contacts)
2. The AccountID in the tbl_Accounts table is sequentially number from 1 to 2200 due to it being the primary key set to autonumber. This happened during the import process. However, the AccountID (FK) in tblContacts is left blank.
Now for my question....
I am wanting to do a query to populate the AccountID field in the Contacts table with the exact same AccountID in the Accounts table, but with one condition...
I need the AccountID from the Accounts table to be the same ID in the AccountID of the Contacts table in the records that have the same AccountName.
Look at the attached screenshots. You will see in the Contacts table, noted in red the duplicated AccountNames listed because there is more than 1 contact for that account. You will also see in the second screenshot (Accounts Table) noted in Blue...the AccountID automatically generated when doing the import.
NOTE - I manually typed in the AccountID into the Contact Table in the field you see in the screenshot. I did this just for the purpose of example. Normally those records as well as all the records in the Contacts Table in the AccountID field are blank.
So again my question - how do I write a query to populate the AccountID in the Contacts table with the AccountID from the Accounts Table using the respective ID number from the AccountName?
Finally, please remember...I am not a DB admin nor a programmer or even very good with SQL...so any advice with very simple (treat me like Im 10 years old and dont know anything about Access.... heh heh
) would be very very appreciated as I have been battling this for days now.
Thanks!
-mgm


Anyway, I have two very large tables in my database:
tbl_Accounts
AccountID (PK)
AccountName (Short Text) joined in a 1 to many (left to right) relationship with AccountName in tbl_Contacts
AccountPhone (ShortText)
AccountFax(Short Text)
AccountBillingStreet1 (Short Text)
AccountBillingStreet2 (Short Text)
AccountCity (Short Text)
AccountState (Short Text)
AccountZipcode (Short Text)
tbl_Contacts
AccountContactID (PK) Autonumber
AccountID (FK) number
AccountName (shorttext) joined in a 1 to many relationship with AccountName in tbl_Accounts
FirstName (shorttext)
LastName (shorttext)
OfficePhone (shorttext)
MobilePhone (shorttext)
Email (shorttext)
I have already imported the data into both tables from spreadsheets and tbl_account table holds 2200 records. tbl_Contacts holds 8800 records
The reason the contacts table hold more records is because, for many of the accounts; there are many contacts specific to that account. In some cases, I could have a 100 contacts for one specific account. Two more pieces of info before I ask my question...
1. In each of these tables, the AccountName field holds the exact same name. However, in the Contacts table, there is multiple records with the same accountname. (due to some accounts have multiple contacts)
2. The AccountID in the tbl_Accounts table is sequentially number from 1 to 2200 due to it being the primary key set to autonumber. This happened during the import process. However, the AccountID (FK) in tblContacts is left blank.
Now for my question....
I am wanting to do a query to populate the AccountID field in the Contacts table with the exact same AccountID in the Accounts table, but with one condition...
I need the AccountID from the Accounts table to be the same ID in the AccountID of the Contacts table in the records that have the same AccountName.
Look at the attached screenshots. You will see in the Contacts table, noted in red the duplicated AccountNames listed because there is more than 1 contact for that account. You will also see in the second screenshot (Accounts Table) noted in Blue...the AccountID automatically generated when doing the import.
NOTE - I manually typed in the AccountID into the Contact Table in the field you see in the screenshot. I did this just for the purpose of example. Normally those records as well as all the records in the Contacts Table in the AccountID field are blank.
So again my question - how do I write a query to populate the AccountID in the Contacts table with the AccountID from the Accounts Table using the respective ID number from the AccountName?
Finally, please remember...I am not a DB admin nor a programmer or even very good with SQL...so any advice with very simple (treat me like Im 10 years old and dont know anything about Access.... heh heh

Thanks!
-mgm

