ms-access: edit form entries using foreign keys - forms

To keep it simple there is the following table relation in ms-access: T_Create (n:1) T_Employee [foreign key is CR_Employee which contains the EM_ID)
The tables look like this:
T_Create (CR_ID, CR_Employee)
T_Employee (EM_ID, EM_Name)
To show the EM_Name field for my T_Create entries I create a query that joins on T_Employee and gets the field EM_Name. So I receive a list that contains the entries of the T_Create table with the fields CR_ID and EM_Name.
I created a form with help of the query. I want to be able to edit the entries with a dropdown menu and save it in the table T_Create. I know how it works, when I display the CR_Employee foreign key field. But I want to change the value without using this field. The form should update the foreign key in the background. In the form I want to use the text that is linked to the foreign key.

You want combobox to save the EM_ID but display the EM_Name? Use a multi-column combobox.
RowSource: SELECT EM_ID, EM_Name FROM T_Employee
ColumnCount: 2
ColumnWidths: 0";1"
BoundColumn: 1
ControlSource: CR_Employee
BTW, name parts should be in separate fields like: FName, LName, MName. Then RowSource could be: SELECT EM_ID, LName & ", " & FName AS FName FROM T_Employee;.
No need to include T_Employee in the form RecordSource unless there are more fields you want to display, such as address info. If you do include T_Employee table then set any controls bound to its fields as Locked Yes and TabStop No.

Related

ms access form listbox changing whole field

I have created a form to update a query that that is in turn based on a master table containing information on a number of files. This master table is then related to several other tables in say for example a table called group_table, defining which group the file would belong to, which contains an ID field and the group_name. This is then related in a one-to-many relationship with the master table based on the group.ID and a field in the master table master_table.group and joined in the query the form is based on.
In the form I have designated a listbox control to update the group field of the query/master table. The contents available for selection in the list box were set based on the group_name field from the group_table table which is defined in the RowSouce section of the property sheet of the form.
So my issue is that when I try and update any records in the query using the listbox in the form, all of the records that are the same will get changed as well. E.g., changing a record in one row from "Group A" to "Group B" will change all the records containing "Group A" to "Group B" in the group field. So I was wondering if there is anything I can do to set it so only the specific record that I want to change gets changed.
When you are making the call to update the table you should make sure that you are using WHERE along with the primary key to make sure that you update that row only. An example would be a statement similar to the one below.
CurrentDb.Execute "UPDATE [group_table] AS G INNER JOIN [master_table] AS M
ON G.[ID] = M.[groupID]
SET G.[group] = '"& Group A & "'
WHERE M.[groupID] = '" & groupIDFromForm & "';"
Apply the ON from the join so that the foreign key and primary key are going to share the same value, and from there use the form to create a variable that you can use to identify the exact row. From there the program should execute the query correctly.

Copy Field contents from one Table to another table - FileMaker

I am new to Filemaker pro. I am working with Filemaker pro 13.
My database contains 3 tables:
category (fields = _pkCatID & CatName)
subcategory (fields = _pkSubcatID , _fkCatID & SubcatName)
books (many fields including _fkSubcatID)
I have no problems in conditional value lists, so making two popup menus in books layout for categories and subcategories was successful.
But I want to put both categories and subcategories in one menu/sub-menu using 2empowerfm Menu Popper plugin.
I created a new field in subcategory table to store a calculation to be used in the value list of the plugin.
The calculation is = CatName & ">" & SubcatName & ";" & _pkSubcatID .
So the returned value when choosing in books layout will be "_pkSubcatID".
The problem is CatName is not in Subcategory table, and if I choose it from the related table Category, I can't make the calculation "stored" which is a requirement to use a field in a value list.
So, I need to copy the field CatName from category table to a new created field in subcategory table. I don't know how to do it.
You just need to create a lookup field in your subcat table pointed to the category name in the category table.
Create a field in the sub-cat table called "Category"
Click on Options
Auto-Enter Tab at the bottom, check "Looked-up value"
Select the correct starting (subcat) and related (Cat) tables and select the name field for the Category.
That is all.
To populate this for existing records click into the _fkCatID field on a subcat layout after showing all records and in the menus select Records->Relookup Field Contents
#Michael Wallace answer is correct and that solution should work.
I'd add however that if the table is likely to become large (and it could do if you're cataloguing books for a library) then I'd suggest you run some tests on a fake large data to see if this menu technique holds up (especially if you are serving over a network). Running two global search fields with an executeSQL lookup for subcategory within category would be more efficient in a big data set - this technique is well described here and other places:
http://forums.filemaker.com/posts/c4ed6f9923

Replacing numeric foreign key with dropdown in Libreoffice Base

I'm building a form for entering credit/debit transactions, so I have two tables in PostgreSQL
accounts
id INTEGER PRIMARY KEY
name VARCHAR(128)
ledger
id INTEGER PRIMARY KEY
credit INTEGER NOT NULL REFERENCES accounts
debit INTEGER NOT NULL REFERENCES accounts
date DATE NOT NULL
amount NUMERIC(8,2)
text VARCHAR(128)
I have built a form with a single table control, listing accounts.name, and a subform that references that control for selection.
Inside the subform, there is another table control, showing date, credit, text and amount after matching debit against the selected entry in the master.
So far, that works, however the credit column has the numeric foreign key data inside a numeric field. I'd like to have a dropdown field that allows me to select an account in its place.
Is that possible, or should I go for a fallback solution with a readonly table populated from a query, and separate edit fields in a subsubform?
The functionality that works in LibreOffice is a listbox. What is tricky is that the individual fields on the grid/table control are not displayed in the form navigator. However, you can convert the type of field on the grid to a listbox by going to edit mode and right-mouse clicking on the header row/column selector of the grid. In the dropdown menu, select "replace with" and "list box". Now that field/column in the grid is a list box.
Then open the "control" dialog and click again on the appropriate header/column selector in the grid, which you just changed to a listbox. Go to the "data" tab. Under "type of list contents" select "Table" and "List content" select the foreign key table. With the "bound field" having a value of "1", the dropdown list will display the first column of the list source, and it will use the value of the second column to populate the data source displayed in the listbox control.
For a better aesthetic, in the control box, "General" tab, "Dropdown" option select "Yes".
The steps above will provide a functionality mostly indistinguishable in the UI from a familiar combobox. You also can try the "combobox" functionality directly in LO, but support for that field type is not as strong.

MS-Access, form to view one entry from one to many relationship

I have a table with Orders and a subtable with itemId's (one to many relationship)
In the form i have a Combobox to select a specific Order and another Combobox to select a specific itemId.
For this i have made a Query to view all aviable itemId's in the second Combobox.
I dont know how to view the selected itemId-data in the form.
You can use the Where argument of the Openform action to specify the item.
OpenForm FormName, , , "ItemID=" & ComboName
-- http://msdn.microsoft.com/en-us/library/aa141520(v=office.10).aspx
This assumes that the bound column of the combo is a numeric ID that relates to an ID in the form to be opened.

How to fill a field in a form with a query, based on data in the form in MS 2007

I'm new to access. I have 2 tables, Artists and Paintings, and have made a form from Paintings (displaying all of the fields in that table). It has a reference to the primary key (id) of the Artist table. I have added another text box to the paintings form, and want to display the artist name, based on the id I already have. How can I get this data displayed?
Thanks
Use the combobox wizard to add a combo box based on the artists table with a control source set to the ArtistID.
It will have properties on these lines:
Control Source : ArtistID
Row Source: SELECT ID, ArtistName FROM Artists
Bound Column: 1
Column Count : 2
Column Widths: 0cm;2cm