Access 2010 - display related record in a form - relational-database

I have 2 related tables.
Invoice (fields: number, buyer, supplier, etc.)
Company - all buyers and suppliers (fields: name,etc.)
Buyer ans supplier fields on invoice are referencing same field (company_id from company table)
On invoice form, I choose supplier ID from dropdown list and also buyer ID from dropdown list.
Task: To make the form little bit readable, I would like to automatically display a name of company after selecting company id in both fields.
What I did:
I manually dragged the company name field to the form and wizard asked me which field I would like it to connect to (byuer or supplier), so I got 1 field working. How to create another field that shows company name? If I drag another instance of company name, wizard does not show so I can set it up and I can not find anywhere setting for that. Thank you for help.

I think the best way is the following:
Create a lookup query: Create a new query similar to this “SELECT CompanyId, CompanyName FROM t_Companies ORDER BY CompanyName;” and save it as “ql_Companies”
Edit your Invoice table. For both your fields Buyer and Supplier do the following: Click on the field and select Lookup in the filed properties. Set the following properties: Change Display Control = Combo Box, Row Source = ql_Companies, Column Count = 2, Column Width = 0;5 and save the table.
Now when you create a new form based on your Invoice table the field will be automatically shown as a combobox.
You can also do all this manually on an existing form but then the combo box will only show on this one form. If you prepare the underlying table with lookup queries then this will work in all queries and forms automatically without additional work.

Related

Show Sum of query results based on main form in text box

I have created a basic database in Access 2013 for project management.
Therein I have set up a main table called Project-properties which holds Project ID as a unique identifier and other fields for project properties. This table is linked via a 1:n connection to another table called Invoices which holds all invoices corresponding to a unique project.
I then went on to create a form based on the Project-properties. On this form I want to display a text field showing the sum of all invoices corresponding to the selected project.
Imagine I have 10 invoices spread across 4 projects, with $10k each resulting in a total of $100k. What I want show in the form is only the sum of the invoices corresponding to, let's say project ID 01. In the Invoices table, only 3 quotations correspond to this project ID with $10k each, so the aforementioned text field should show $30k.
I have tried with =Dsum('InvoiceSum';'Invoice') but I only get the sum of all projects $100k.
DSum (and associated domain lookup functions) have a third argument that allows you to specify a filter.
If the project field is a string, then you would use something like:
=DSum("InvoiceSum","Invoice","ProjectID='ID01'")
If you wish to have the filter dependent on a variable, then this would become:
Dim strProject As String
strProject="ID01"
=DSum("InvoiceSum","Invoice","ProjectID='" & strProject & "'")
If this is a control on a form, and the Project ID is numeric, then you would use this as the control source of a text box, as long as ProjectID is included in the Recordsource of the form:
=DSum("InvoiceSum","Invoice","ProjectID=" & ProjectID)
Regards,

Cannot add record(s); join key of table not in recordset in MS Access

I'm new to access, and I have been able to find a solution for most of the hiccups I have experienced with MS Access, but I cannot get a combo box in a form to function properly.
I have tried unbounding it, but then it does not update the corresponding field in the query the form is based on. I have tried to bound it to the EmployeeID, but then cannot select the Employee in the combo box because EmployeeID is an autonumber field.
If anyone can offer me any advice on how to get this to function properly, it would be greatly appreciated. Also, the basic intent of the form is to allow an employee to select their name, enter a date, and check the appropriate boxes. All of the other values function properly, but I do not want the Employee table to change every time a maintenance log is created weekly...
I hope I explained everything well enough. Attached below is a copy of the database.
Maintenance Log Database
You have to set up the combo box with a row source that contains both the Employee ID and the Employee Name. Use Employee ID as the bound column. Then in the display properties set columns to 2 and column widths to 0;1 (assuming you set your row source so that Employee ID is column 1 and Name is column 2).
This way your combo box displays the name but it actually binds to and uses the ID.

Query a table by value in main form and load subform - Access 2007

When I open Order Form, it should show the list of products already present in that order in a 'ProductsCartForm'
My tables are as below:
OrderTable:
OrderId - Autonumber
CustName
ShipAddress
Amount
ProductCartTable
ID - unique
OrderId - one orderId may hold many productIds
ProductId
Quantity
UnitCost
I want to create 'ProductCartForm' in my main form 'OrderForm'. I have a parametrised query 'qryProductsByOrderId'. If I create a subform based on qryProductsByOrderId, how can I pass the parameter 'orderId' to the subForm before/on Loading.
Some one pls help.
Thanks.
Like Roland says, no VBA necessary. This is what Access does well :)
Make your form for your Orders (necessary to have record source of OrderTable). Then make your form for your Products (doesn't need to be perfect, just needs to exist and have a record source of ProductCartTable). Save both. Close the Products form.
Go into your Orders form and drag your Products form on it. This will create the products form as a subform. It will likely populate the Master/Child links for you but if it does not you just need to write in OrderID for both because it is what joins the two record sets together.
This effectively does a left join for you. Only product records which are relevant to the order being shown will show on the subform.

How to select multiple records and change their value at once

Here is my problem and I do not know where and how to start to search about this.
In a MS Access database users will have a list of records returned from a query. Let's say employees which are active (employed). This table has a related table let's say departments (related through departmentID in both table).
What I want to do is to make form (or something else which would do the same job), where user will select some records (probably with checkboxes associated with each record) and there will be a single combobox with department names. When user selects a department name, its departmentID should be saved into departmentID field of these records.
I have created a form with a query of active employees (form with multiple items). And put an extra field in Detail section with a checkbox. In Form footer I have a combobox with Department names and IDs (not shown to user), and a button to save values.
I have to now figure out, how to select all rows/records with a checked checkbox and update them. I am by the way familiar with VB and SQL.
I would appreciate any idea/knowledge on how to solve this.
An extra field in the Detail section won't help you if you don't link it with a data field in the displayed table. If you can do that, then you have simply to make a VBA function to update all selected rows, and refresh the recordset.
If you cannot modify your table, you'll have to create a new table with just the key columns of your master table, and manage it via VBA. Better to use the first option if you can, it pollutes your schema, but in most cases that won't be a problem for an Access database.

MS Access: Choose a option from ComboBox and it automatically updats other text box

What I want to do is choose a option from a combobox- (i.e. a Person ID), and based on that option the form auto populates other text boxes (Person Name, Location, Number)
I have a table with the information. the table contains the person ID along with the the person's information in each record. The table contains 1400 records.
Any EASY WAY to do this. All answers are appreciated. even difficult ones.
Add a subform whose record source is a query such as this ...
SELECT [Person ID], [Person Name], Location, [Number]
FROM The_Table;
Then, from the subform control's property sheet, select the main form's combo box as the link master field and [Person ID] as the link child field. The result should be that the subform displays those additional details for the ID currently selected in the combo box.
That is an easy way to display the details. If your intention was to store those details again in another table, I'll suggest don't do that. Store only the ID and then if you need to display the details in other contexts, use a query to join (based on ID) the two tables.