0

so I stuck at one point at work. I got this table "IP". It has relations to another table. In order to see the "real name" of entity I created a query.

See picture of my query of my IP table --> host / hostname

I want to create a form to edit entries in tbl_IP. In this form I want to show the related name of the Host in order to see on which IP I'm looking at.

But when I create a form based on this query I can see the information but cant edit it.

I guess it is realted to the fact that the query has relations to another table. But at this point I'm not experienced enough.

Can someone explain how to do this?

Thanks in advance.

McGrady
  • 10,869
  • 13
  • 47
  • 69

1 Answers1

0

I think an example is worth a thousand words. Download this example which I hope is what you want.

enter image description here

Uses this

enter image description here

You can poke around to see how the rest of it is built I think.

After you insert the table control, you need to right click on the fields to change Host ID and Port ID from a numeric field to a List box field.

(Note that combo boxes can't be used for this in LO because they only operate on a single field and you need two fields, an ID and something that is the human readable reference to that ID. In Access either combo or list boxes will work.)

I purposely made the Hosts lookup use a query and the ports lookup use SLQ so you could see the two most common ways of getting the pull down list.

Sometimes SQL is better and sometimes Query is better, depending on what you're doing. If your tables are laid out just so, you can use the table directly for your pull down, i.e. field1=displayed text or value, field2=ID key, in that order. But as a rule I like to keep my Key ID as the first field in all of my tables, so never use this method.

Also I've related the tables with Left or Right Join rather than Inner Join. I almost never use inner join because when used to link two tables in a query it hides records from both tables if either is missing, rather than displaying the missing data as empty containers which I prefer.


Other unasked for general design tips I've worked out over the years which I hope you'll consider:

  • I find naming tables in the plural and records in the singular, and carefully sticking with this, makes the most sense, e.g. the IPs table (contains multiple IP records), and IP ID, is the integer representing or pointing to a specific record. Sometimes words like Data are plural without an 's', so you'll use Datum for the record and Data for the table.

  • I think giving pointers and targets the exact same name is most helpful, especially as your database grows and there is confusion as to what points to what. It's just simpler to keep the two names the same, and more bomb proof. In other words use a field named Host ID in a primary table and this points to a field named Host ID in lookup table. (Others call this a foreign key lookup, but I've never found that name very helpful).

  • And I always try to name the primary key using the table name itself suffixed by ' ID', never some other word or string of text. That way when I look at an ID I know for sure which table it's associated with. So for example, if the table is named Hosts, then the primary key is always Host ID (not Hosts ID because that would be plural, when in fact an ID refers to only one record, not all of the records). For example, IP ID, or IP_ID of you like both work fine. I find that IP ID (with a space) reads and types more easily, because it allows more complex names with multiple words, like Word1 word2 word3 ID. Space is easier to type than underscore. But this assumes you'll have to quote all of your identifiers, which I always do, but is not always required. I like strict conformity to a few basic rules like this.

Hope this helps you.

Elliptical view
  • 3,338
  • 1
  • 31
  • 28
  • This looks quit good for me. But I need one more function on this... Is there a way to search for specific Hostname before listing the IPs? So I just see the IPs of that specific Host. I know that I can let a query search for specific name (LIKE '%' || :Hostname || '%') but I just can't use such function with a form like yours. – Sethologik Apr 27 '17 at 12:13
  • Change how Hosts is joined (switch right/left). Then specify your host as a condition in your query. There are other ways to search, but that is the subject of another question. Suggest you also take a look at ask.libreoffice.org – Elliptical view Apr 28 '17 at 19:07
  • Do I need to let it search in the query or is there another method which would be easier? – Sethologik May 05 '17 at 06:52
  • Sorry, I lost track of what you're trying to do. Can you clarify your question more? – Elliptical view May 07 '17 at 04:41
  • Sorry. I try to sum up... With your help I created a form in LibreOffice Base in order to edit the entries of the "IPs" Table. But for now I am just able to edit the entries in a loooong list of all entries. Now I want a "search" function so I can edit the entry of a specific Machine... In the "IPs" Table the information of Machine is just the ID of it (normalization). So I can't just let the program search of a machine in the query because it wouldn't let me edit the IP information then. Was this helpful? :) – Sethologik May 08 '17 at 18:36
  • Most of the time I keep my keys separate from my data. The only time I break this rule is for simple tables that are only edited at setup. In other words, tables of standard items similar to enumerations. Otherwise sometimes I have had trouble editing the data. I don't know how big your table is, but here ( https://ask.libreoffice.org/en/question/81114/base-adding-multiple-pull-down-record-selectors-to-a-table-editor-form/#85545) is one way I developed to be able to more easily search for and edit records. It might work for you. Also there is filter approach to searching. – Elliptical view May 09 '17 at 23:36