Assigning an ID based on similar field of a different table (2 Viewers)

Stez

New member
Local time
Today, 01:58
Joined
Jul 12, 2023
Messages
9
Hello,

I have two tables, one with the Businesses and its individual ID for each business along with some information for each such as addresses. In the other table, I have reports for each business but no ID, I want to link each report so it updates with the ID of the first table using information such as the address. How can I accomplish this?
 

plog

Banishment Pending
Local time
Today, 03:58
Joined
May 11, 2011
Messages
11,646
I could barely parse that. Some sample data from both tables could probably clear things up.

However, I think I heard that you have 2 tables that you want to JOIN, however you haven't explicitly defined a way to JOIN them. So, take computers out of the question for a minute--when you look at the data in those 2 tables how do you know that some rows in 1 table go with some rows in the 2nd table? If a person had only pen and paper how could they deduce the connection between the data?

On second thought, we definitely need sample data so you can illustrate how you know the data in one table belongs to data in the second.
 

Stez

New member
Local time
Today, 01:58
Joined
Jul 12, 2023
Messages
9
I believe these tables might make it clear, so in the reports list, there are multiple reports per business and I want the ID field to automatically match the ID field from the business list using the business name, street #, and street name. However, all three of these fields are never inputted exactly the same but should be similar.

Business List
IDBusiness nameStreet #Street Name
23Starbucks123El Camino


Reports List
IDReport DateBusiness NameStreet #Street Nameetc
Blank (automatically input as 23)7/10/23Starbucks123El Caminotrash
Blank (automatically input as 23)7/12/23Starbucks123El Caminowater
Blank (automatically input as 23)7/14/23Starbucks123El Caminogas
 

mike60smart

Registered User.
Local time
Today, 09:58
Joined
Aug 6, 2017
Messages
1,905
Hello,

I have two tables, one with the Businesses and its individual ID for each business along with some information for each such as addresses. In the other table, I have reports for each business but no ID, I want to link each report so it updates with the ID of the first table using information such as the address. How can I accomplish this?
Hi Stez

You should have 2 tables with the following structure so that you can set a Relationship
between the Business and the Address.
We would link the Parent PK BusinessID from tblBusiness to the BusinessID FK BusinessIDin tbleAddress
 

Attachments

  • Business.jpg
    Business.jpg
    43.5 KB · Views: 47

mike60smart

Registered User.
Local time
Today, 09:58
Joined
Aug 6, 2017
Messages
1,905
I believe these tables might make it clear, so in the reports list, there are multiple reports per business and I want the ID field to automatically match the ID field from the business list using the business name, street #, and street name. However, all three of these fields are never inputted exactly the same but should be similar.

Business List
IDBusiness nameStreet #Street Name
23Starbucks123El Camino


Reports List
IDReport DateBusiness NameStreet #Street Nameetc
Blank (automatically input as 23)7/10/23Starbucks123El Caminotrash
Blank (automatically input as 23)7/12/23Starbucks123El Caminowater
Blank (automatically input as 23)7/14/23Starbucks123El Caminogas
Your Reports List structure is wrong.
Yo would not store the actual Business Name. If you set the Business table as the Main Parent Form for Data Input
then you would have a Subform for the Address's with a FK of BusinessID
 

mike60smart

Registered User.
Local time
Today, 09:58
Joined
Aug 6, 2017
Messages
1,905
I believe these tables might make it clear, so in the reports list, there are multiple reports per business and I want the ID field to automatically match the ID field from the business list using the business name, street #, and street name. However, all three of these fields are never inputted exactly the same but should be similar.

Business List
IDBusiness nameStreet #Street Name
23Starbucks123El Camino


Reports List
IDReport DateBusiness NameStreet #Street Nameetc
Blank (automatically input as 23)7/10/23Starbucks123El Caminotrash
Blank (automatically input as 23)7/12/23Starbucks123El Caminowater
Blank (automatically input as 23)7/14/23Starbucks123El Caminogas
Can you upload a copy of your database?
 

Stez

New member
Local time
Today, 01:58
Joined
Jul 12, 2023
Messages
9
Sorry, that wouldn't be possible.

I understand that it would not store the actual business name but that is how it was already, I believe it can just be ignored even if it is useless?
 

mike60smart

Registered User.
Local time
Today, 09:58
Joined
Aug 6, 2017
Messages
1,905
Sorry, that wouldn't be possible.

I understand that it would not store the actual business name but that is how it was already, I believe it can just be ignored even if it is useless?
You should take advice and NOT ignore this.
Best to bite the bullet and sort this before you go much further with your design.
 

The_Doc_Man

Immoderate Moderator
Staff member
Local time
Today, 03:58
Joined
Feb 28, 2001
Messages
27,186
To answer the direct question, you can write a query to attempt this update. This could be defined on one line but I broke it up for clarity.

Code:
UPDATE [Reports List] As R INNER JOIN [Business List] As B
    ON R.[Business Name] = B.[Business Name]
        SET R.ID = B.ID ;

However, this would be a one-time thing and DOES DEPEND in the business names being spelled correctly in each record of each table. After you ran that query, you would then have to check for the Reports List to still have blanks. Those blanks would imply a name in the Reports list that doesn't match any names in the Business list. Whether it is a spelling error or an error of omission in the Business list would be for you to decide. Keep that query around until you can fix all the names that don't match up correctly, because it is a safely repeatable query. I.e. if you ran it twice, the worst it would do the second time is overwrite the Reports List ID with the same thing that had been loaded previously.

Now, as a side note... The Reports List table is a dependent table in this context whereas the Business List table is an independent table. Therefore the Reports List ID is a foreign key to the (at least potential) primary key represented by the Business List ID. It is considered bad form to just call fields "ID" - particularly when they might appear in more than one table. For instance, you might call the Business List ID "BusID" and in the Reports list call the corresponding field "BusFK" - which becomes a name full of meaning - a foreign key to the business list.
 

Stez

New member
Local time
Today, 01:58
Joined
Jul 12, 2023
Messages
9
To answer the direct question, you can write a query to attempt this update. This could be defined on one line but I broke it up for clarity.

Code:
UPDATE [Reports List] As R INNER JOIN [Business List] As B
    ON R.[Business Name] = B.[Business Name]
        SET R.ID = B.ID ;

However, this would be a one-time thing and DOES DEPEND in the business names being spelled correctly in each record of each table. After you ran that query, you would then have to check for the Reports List to still have blanks. Those blanks would imply a name in the Reports list that doesn't match any names in the Business list. Whether it is a spelling error or an error of omission in the Business list would be for you to decide. Keep that query around until you can fix all the names that don't match up correctly, because it is a safely repeatable query. I.e. if you ran it twice, the worst it would do the second time is overwrite the Reports List ID with the same thing that had been loaded previously.

Now, as a side note... The Reports List table is a dependent table in this context whereas the Business List table is an independent table. Therefore the Reports List ID is a foreign key to the (at least potential) primary key represented by the Business List ID. It is considered bad form to just call fields "ID" - particularly when they might appear in more than one table. For instance, you might call the Business List ID "BusID" and in the Reports list call the corresponding field "BusFK" - which becomes a name full of meaning - a foreign key to the business list.
I believe this could also be done by having the query find business reports with similar names and addresses to then assign it automatically to the corresponding business ID?
 

plog

Banishment Pending
Local time
Today, 03:58
Joined
May 11, 2011
Messages
11,646
However, all three of these fields are never inputted exactly the same but should be similar.

Describe this process please. Specifically how is the data input?

Are users directly inputting this data via an Access form into the Reports List table? If so, you have designed that form incorrectly. If not, please explain how the Report List is populated.
 

Stez

New member
Local time
Today, 01:58
Joined
Jul 12, 2023
Messages
9
Editing the original sample I made, some of the reports made originally were never made consistently, this is one reason I would like them to have the same ID so it can be easier to access all the reports from a specific business even if the data itself was not entered correctly.

Reports List
IDReport DateBusiness NameStreet #Street Nameetc
Blank (automatically input as 23)7/10/23Starbucks Store123El Caminotrash
Blank (automatically input as 23)7/12/23Starbucks12 3El Camino Avewater
Blank (automatically input as 23)7/14/23Starbucks123El Camino Av egas
 

mike60smart

Registered User.
Local time
Today, 09:58
Joined
Aug 6, 2017
Messages
1,905
Editing the original sample I made, some of the reports made originally were never made consistently, this is one reason I would like them to have the same ID so it can be easier to access all the reports from a specific business even if the data itself was not entered correctly.

Reports List
IDReport DateBusiness NameStreet #Street Nameetc
Blank (automatically input as 23)7/10/23Starbucks Store123El Caminotrash
Blank (automatically input as 23)7/12/23Starbucks12 3El Camino Avewater
Blank (automatically input as 23)7/14/23Starbucks123El Camino Av egas
Plog asked how was the data entered into this table?
Was it entered directly into the table or was a Data Input Form used.
It looks like you have data for 3 Records which should be for the same Business Name, but due to bad data input we have 3 corrupt records.
 

Stez

New member
Local time
Today, 01:58
Joined
Jul 12, 2023
Messages
9
Sorry, it seems as if they have been just inputting it manually into the table.

I think the best way to input such reports is in the business list, having the option to open up a report form which will then have all the basic business information always saved and be consistent.
 

mike60smart

Registered User.
Local time
Today, 09:58
Joined
Aug 6, 2017
Messages
1,905
Again we are getting nowhere fast.

Tables are where we store Data
Reports is a means of displaying Data from 1 or more Tables.

What you would normally have is a Form for Data Input into Related Tables.

In your process would you want to be able to Select a Business Name and then enter
1 or More details (Records) related to that Business Name?

If this is the case then you need a Main Form based on Business Names
With a Subform based on Business Reports (I think this name does not reflect your actual business)
 

Stez

New member
Local time
Today, 01:58
Joined
Jul 12, 2023
Messages
9
Again we are getting nowhere fast.

Tables are where we store Data
Reports is a means of displaying Data from 1 or more Tables.

What you would normally have is a Form for Data Input into Related Tables.

In your process would you want to be able to Select a Business Name and then enter
1 or More details (Records) related to that Business Name?

If this is the case then you need a Main Form based on Business Names
With a Subform based on Business Reports (I think this name does not reflect your actual busines

Having a form that will have a business list subform where I would be able to pick individual businesses and have the ability to open a form for each business where I would be able to input a 'business report'
 

mike60smart

Registered User.
Local time
Today, 09:58
Joined
Aug 6, 2017
Messages
1,905
Having a form that will have a business list subform where I would be able to pick individual businesses and have the ability to open a form for each business where I would be able to input a 'business report'
Can you give us all an example of all the Data for a Typical Business Report
 

Stez

New member
Local time
Today, 01:58
Joined
Jul 12, 2023
Messages
9
Date of each business report, type of report, reason for reporting, follow-ups, comments

It would be like a periodic thing.
 

mike60smart

Registered User.
Local time
Today, 09:58
Joined
Aug 6, 2017
Messages
1,905
Date of each business report, type of report, reason for reporting, follow-ups, comments

It would be like a periodic thing.
Sorry If you can't give me an example of a Typical Report then I can't help you further.
 

jdraw

Super Moderator
Staff member
Local time
Today, 04:58
Joined
Jan 23, 2006
Messages
15,379
Stez,
Can you step back and tell us using simple, plain English about your business at the 30,000 ft level, and the what, when and why of the various reports?
Consider this hypothetical: Often there is a list of Customers who may Order many Products and/or Services from your Organization. Management wants reports at quarter end, year end etc to determine "How's the business doing".

Readers need something concrete to work with and advise/suggest accordingly.
 

Users who are viewing this thread

Top Bottom