Feasibility of data entry form with dropdown menu for foreign keys

TL;DR
Currently, I do not use forms for data entry in Base.
When I add a value into a table, which is represetend by a foreign key in another table, I manually enter the key.
Is it possible to create a data entry form for db.table, which allows me to select values in a dropdown menu from the foreign table db.table2 displaying the field db.table2.name, which adds the key db.table2.id to db.table.table2_id?

Backgroud
I use a MariaDB database for tracking information on my biological specimens in amateur microscopy and botany. Because I want to avoid writing a custom frontend, I am experimenting with LibreOffice Base for querying the DB. For reference I will attach a diagram of tables relations.
Specifically I would like to create data entry forms for my tables sample, slide and organism.
For fields represented by foreign keys, instead of a box for typing text, I would like to create a dropdown menu displaying a human readable field of the foreign table (like name) to select the foreign key.

I much apprechiate any help on this matter, as I was unable to find a guide on how to accomplish this.

Please have a look at this thread:

Nearly the same question: I described there how to create a list box, which show the content of a field of one table and saves the foreign key in the other table.
You have a table “slide”.
You create a table for “sample” with a subform “slides”.
In subform “slides” there are 3 other foreignkeys. All this keys will be filled by list boxes.
You will show “section”.“name” and save “section”.“id” in “slides”.“section_id”
… and the same way for “mounting_medium” and “staining”

Might be you want to put “sample” also as a list box, not as mainform. But there is many content in “sample” so I thought it has to be filled first before “slides” will be filled with content.

1 Like

Thank you very much, this answered my question! :smiley:

Just for reference, I was able to implement the solution accomplishing a clean looking data entry form.

How did you manage, that the combobox shows the selected text an not the id once you selected an item?

In my case the combo box shows text only in the list of the expanded combobox, but the id when the combobox is collapsed (see screenshot).

Thank you

Bildschirmfoto 2024-12-30 um 12.57.45

A combo box is just the same as a text box plus auto-complete. It stores the displayed text in the linked field.
A list box is made to store another table’s primary key in the form’s foreign key by selecting a corresponding text. A working listbox consists of 2 columns:
#0 is the visible text
#1 is the bound field which is the other table’s primary key to be be written into the form’s foreign key.
A typical 2-column source for a listbox looks like SELECT "Name", "ID" FROM "table" ORDER BY "Name" ASC

1 Like

Thank you for this explanation for understanding how it works!
I changed to list box and it works fine.