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

Akhater
Akhater used Ask the Experts™
on
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
Comment
Watch Question

Do more with

Expert Office
EXPERT OFFICE® is a registered trademark of EXPERTS EXCHANGE®
Ryan ChongSoftware Team Lead

Commented:
>>Table1ID INTEGER NOT NULL CONSTRAINT FK_Table1ID  
        REFERENCES Table1 (Table1ID)

you had already referred to the field name, which is Table1ID
Ryan ChongSoftware Team Lead

Commented:
meaning to say...

FK_Table1ID  
        REFERENCES Table1 (yourfield)

in your case, change "yourfield=" to "name="
Ryan ChongSoftware Team Lead

Commented:
typo. in your case, change "yourfield" to "name"
Should you be charging more for IT Services?

Do you wonder if your IT business is truly profitable or if you should raise your prices? Learn how to calculate your overhead burden using our free interactive tool and use it to determine the right price for your IT services. Start calculating Now!

AkhaterSolutions Architect

Author

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 Professional

Commented:
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

Solutions Architect
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"
Hamed NasrRetired IT Professional

Commented:
This suggests the properties of a combo box, and comes under data display.
Ryan ChongSoftware Team Lead

Commented:
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.
Distinguished Expert 2017

Commented:
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 Architect

Author

Commented:
Thank you for the help
solved it myself

Do more with

Expert Office
Submit tech questions to Ask the Experts™ at any time to receive solutions, advice, and new ideas from leading industry professionals.

Start 7-Day Free Trial