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

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.

Related

Access add more than one record at a time using subform

Hello, so I need some help. The image attached is the form I'm working on. I got it working up until the point I can save that record and go back to my query where training records are and see it in there. The save button does not clear any info out of the form, but if I do change the id of 345 to say 346, it won't make a new line. It just rewrites over the 345 in the record. However, what I fully intend to do is have this store multiple records at once and the subform is where you can see what you're going to add once you hit save. This is my first big project, so speak in noob terms. Thanks!
I think I understand what you're trying to do and I'll use an example of a customer with multiple orders to explain how to use a subform to add multiple orders to the same person.
First, you want to have the Customer_ID and then a Product_ID. In the Product_ID table, make sure you have a field called "Customer_ID" which will act as the foreign key that will reference the Customer_ID field in the Customer table. When you add a subform to the Customer form, you set the "Master Field" and "Child Field" to the "Customer_ID". This will allow the subform to reference the Customer_ID field and maintain the relationship and a unique Product_ID (not Customer_ID) will be generated each time you add a record to the subform.
Select the subform and go to "Property Sheet>Data" and double-check the link in the master and child field.
Simple 1-to-many Employee-Task relationship
How the relationship should look like with the Subform
What the main form and subform should look like. You can do something similar with the Standard List Table based on the relationship you've established.

Filtering subforms using multiple ID values, no record source changes

I've coded my entire database to rely on recordsets and updating those recordsets on click of record IDs within other forms. Then I discovered that I can't edit the records from the datasheet. So I need an alternative.
My database consists of the following tables: Customer, Address, Order, Details, Contact and Misc. Each of these tables has a PK which is stored in a table called Master_Bridge which constructs a unique combination of all the PKs.
I have a form which includes each of these tables as a subform. The user begins at the Customer subform. When they click the Customer_ID, the Address table needs to filter based on where that Customer_ID exists within the Master_Bridge.
I was hoping to store each of the IDs into a recordset, or an array of some type, and translate each of those values into the filter. Admittedly, my VBA isn't good enough that I know how to do that.
I also tried a nested select in the recordsource of the Customer form, where I selected all of the Address_IDs. Again, couldn't edit.
Do you folks have any suggestions on how to proceed with this? I'll also need the click of Address_ID to filter the Order form by using both the Customer_ID and the Address_ID. The rest of the tables/forms will utilize the above 3 IDs.

Access 2010 - display related record in a form

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.

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 2010: How Can I Avoid Uneditable Query Results?

I am working on my first Access 2010 database and have run into a problem editing the recordset returned from a query. This excellent blog entry details several scenarios which can result in uneditable query results. I believe my query results are not editable because my query has a Cartesian Join.
I'm not sure how to avoid this, however. The three tables involved are:
episodes
Individual television episodes
Primary key: "episode_id"
aridates
Individual airdates for a given episode
Primary key: "airdate_id"
Related to "episodes" by "airdate_episode_id"
startdates
Individual download start-dates for a given episode
i.e. when a given episode will be available to download
Primary key: "startdate_id"
Related to "episodes" by "startdate_episode_id"
So, there is no (and I think can be no) direct relationship between airdates and startdates. However, this makes the query:
SELECT episodes.episode_id, episodes.episode_number, episodes.episode_title, airdates.airdate_region_id, airdates.airdate_date
FROM (episodes LEFT JOIN airdates ON episodes.episode_id = airdates.airdate_episode_id) LEFT JOIN startdates ON episodes.episode_id = startdates.startdate_episode_id;
return a recordset which is not editable. I need to be able to see the episode name and number along with the airdate in order to enter a startdate (episodes can not be made available for download before they have aired). So essentially, in this view I only need to be able to edit "startdates.stardate_date".
Thanks in advance for any suggestions... a screenshot of the relationship in question can be seen here.
Create this query:
SELECT
episodes.episode_id,
episodes.episode_number,
episodes.episode_title,
airdates.airdate_region_id,
airdates.airdate_date
FROM
episodes LEFT JOIN airdates
ON episodes.episode_id = airdates.airdate_episode_id;
Use it as the recordsource for a new form. Then create another form which uses a query of only the startdates table as its record source.
Add the second form as a subform to the first form. On the property sheet for the subform control, make the link master field episode_id and the link child field startdate_episode_id.
If you are successful, the subform will display startdates rows where the startdate_episode_id matches the episode_id of the main form's current record. And if you add a new row in the subform, its startdate_episode_id will "inherit" the episode_id from the main form.
I emphasized control earlier because that point can be confusing. The subform control is a member of the main form's controls collection, and the subform control contains the subform. You must find the link master/child field properties on the subform control, not the actual subform itself.