Access SQL / VBA how to display name instead of ID with relationships

Hi
Assuming I have 2 tables
Table1
Table1ID (Autonumber)
Name (Text)

Table 2
ID (Autonumber)
Table1ID (for table relationship)
wathebver (text)


I want to create table 2 programatically

CREATE TABLE Table2
(
   IDAUTOINCREMENT PRIMARY KEY,
   Table1ID INTEGER NOT NULL CONSTRAINT FK_Table1ID  
        REFERENCES Table1 (Table1ID),
    NoteDate DATETIME
)

this is creating the relationship but the display in the table is the ID from table 1, how can i change that to be the "Name" field in Table1 like when i do it from the wizard in Access?

thank you
LVL 50
AkhaterSolutions ArchitectAsked:
Who is Participating?

[Product update] Infrastructure Analysis Tool is now available with Business Accounts.Learn More

x
I wear a lot of hats...

"The solutions and answers provided on Experts Exchange have been extremely helpful to me over the last few years. I wear a lot of hats - Developer, Database Administrator, Help Desk, etc., so I know a lot of things but not a lot about one thing. Experts Exchange gives me answers from people who do know a lot about one thing, in a easy to use platform." -Todd S.

Ryan ChongBusiness Systems Analyst , ex-Senior Application EngineerCommented:
>>Table1ID INTEGER NOT NULL CONSTRAINT FK_Table1ID  
        REFERENCES Table1 (Table1ID)

you had already referred to the field name, which is Table1ID
Ryan ChongBusiness Systems Analyst , ex-Senior Application EngineerCommented:
meaning to say...

FK_Table1ID  
        REFERENCES Table1 (yourfield)

in your case, change "yourfield=" to "name="
Ryan ChongBusiness Systems Analyst , ex-Senior Application EngineerCommented:
typo. in your case, change "yourfield" to "name"
Acronis True Image 2019 just released!

Create a reliable backup. Make sure you always have dependable copies of your data so you can restore your entire system or individual files.

AkhaterSolutions ArchitectAuthor Commented:
It was the first thing I tried but it doesn't work, "NO Unique index Found for the referenced field in the primary table"

the ID is the unique but i want the name to dispaly

thanks
Hamed NasrRetired IT ProfessionalCommented:
The relation is right.
And this is the stage of collecting data.

Next stage is to display and use data.
To display the name, you need to join the two tables, and include the name in the recordset.

SELECT table1.Id, table2.[name]
FROM table1 INNER JOIN table2  ON table2.table1ID=table1.table1ID

Open in new window

AkhaterSolutions ArchitectAuthor Commented:
no the problem was not from the SQL but from the properties of the table

had to change ColumnCount to 2 and ColumnWidth to 0";1"

Experts Exchange Solution brought to you by

Your issues matter to us.

Facing a tech roadblock? Get the help and guidance you need from experienced professionals who care. Ask your question anytime, anywhere, with no hassle.

Start your 7-day free trial
Hamed NasrRetired IT ProfessionalCommented:
This suggests the properties of a combo box, and comes under data display.
Ryan ChongBusiness Systems Analyst , ex-Senior Application EngineerCommented:
had to change ColumnCount to 2 and ColumnWidth to 0";1"
ok... think it was a bit vague and the issue was not being explained clearly.

anyway, glad that you found the solution.
PatHartmanCommented:
Combos do not belong on tables.  They belong on forms.  There are lots of expert warnings to not use this "feature".  You will run into trouble with VBA and queries.  Since users never open queries or tables directly, only the developer ever actually would see this combo on the table and if the developer needs to see the lookup value, he can create a query that joins the main table to the lookup table.
AkhaterSolutions ArchitectAuthor Commented:
Thank you for the help
solved it myself
It's more than this solution.Get answers and train to solve all your tech problems - anytime, anywhere.Try it for free Edge Out The Competitionfor your dream job with proven skills and certifications.Get started today Stand Outas the employee with proven skills.Start learning today for free Move Your Career Forwardwith certification training in the latest technologies.Start your trial today
Microsoft Access

From novice to tech pro — start learning today.