MS ACCESS Managing deletions with one-to-one relationship - ms-access

I have a working Sales Order form, and I need to add a subform for Returned Goods. I have a one-to-one relationship set up between the ID of my SalesOrderDetails and my SalesOrderReturns, because each line item should never have more than one SalesOrderReturn line item.
I want to be able to delete SalesOrderReturns from the subform datasheet, while not deleting the SalesOrderDetail it's tied to. Let's say it was entered on accident. On the other hand I want to prevent deletion of the SalesOrderDetail if it's tied to a SalesOrderReturn.
The way I have it set up now, I cannot delete SalesOrderDetails if they have a linked SalesOrderReturn. But when I delete the SalesOrderReturn, it deletes the line item in SalesOrderDetails. I just want to remove the Return without removing the line item.

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.

Subform gets records with foreign key, but new records don't get saved with it

I am new to access and trying to create a simple form with a subform. The database has the relationship set. When I select an ID from the combo box linked to the subform, the subform pulls the records with the correct foreign key. However, when I try and add new records, I can't seem to get the foreign key to set with the ID from the combo box. From what I understand it should just save the fk automatically, but nothing I try seems to get it to grab the ID. Here is the link to the simple database so far.
Any specific sections that are of interest I can add.
Thanks!
Don't know how you created the subform, but if you remove the subform and then drag-and-drop the query on the parent form, a new subform is created, and the wizard asks you by default:
Show Order Items for each record in Order by ID
Leave that selected, click next and continue, and your subform now works as expected.

Access: Appending Related Tables

I am working on a small side project. Below is an image of all my relations. I only have the tables set up so far, and a couple Queries that sorted my a couple of my tables a certain way to be used as lookup columns.
Is there a way to append new records to multiple tables at once?
I have experimented with this a few different ways. The thing that stumps me is when I create a form and corresponding sub forms (I can make sub form after sub form that has the entire string of things that could be input across multiple tables, which is not very aesthetically pleasing or easy to use), I have to enter data multiple times. Referring to appending the invoice item as well as the item list tables. I would have to enter the following;
Invoice Number (From invoice item)
Item Code (From invoice item)
Item Code (From item list)
So I end up having to type the item code multiple times, this occurs across the entire chain of tables I need to update in order to create an order.
Also in case you are wondering, all the tables seen in the diagram are update at time a new order is created. (This is a resale business so inventory is never held and item (in the Item List table) are added new at time of order.
So the Invoice table needs to be appended which starts the chain that I am trying to accomplish. Invoice number gets entered which I would like to automatically carry over to Invoice Item in wait for the Item Code to be entered to complete the composite key but without having to type the Invoice number again, and so on and so forth.
This is referred to as a Cascading Update and is essential to enforcing Referential Integrity.
What you want to do is:
Click the relationship line for the relationship that you want to
change. The relationship line appears thicker when it is selected.
Double-click the relationship line. –or– On the Design tab, in the Tools group, click Edit Relationships.
The Edit Relationships dialog box appears.
Select the Enforce Referential Integrity check box.
Select either the Cascade Update Related Fields or Cascade Delete
Related Records check box, or select both.

Calculated control does not recalc automatically

Firstly, a bit about my setup.
I have a primitive database of three tables:
A. Table that lists various locations: [location_code], [location_name]
B. Table that describes items: [item_code], [item_name], [item_price]
and finally a table that ties the roo^H^H^H whole database together
C. Table says which items are stored at each locations and in what quantities: [location_code], [item_code], [item_quantity]. This table can have multiple entries with the same [location_code], since different items can be stored at the same location. Basically, this is a schoolbook implementation of one-to-many relationship from locations to items, with a extra attribute (quantity) attached to each location-item link.
Now, all I need to do is to create a form that would list all items stored at certain location. This is a basic use-case for "subform" feature in Access. The main form simply navigates through different locations, while the subform lists the items.
I use
SELECT C.location_code, B.item_name, B.item_code, B.item_price, C.item_quantity
FROM B INNER JOIN C ON B.item_code=C.item_code
as a record source for the subform. The main form is linked to subform by [location_code]. The subform is set up with list layout (not table layout), i.e. each database field is given its own control element.
So far everything works perfectly. I select the location in the main form, and the subform gives me a list of editable [item_name]-[item_price]-[item_quantity] triplets for the current location.
As the next step, I want to add a calculated control to each of the above triplets. I want to know the total price for each kind of item (i.e. simply the [item_price] * [item_quantity] in each line). Easy, I add a calculated control to the "repeatable" area of the subform and specify
= [item_price] * [item_quantity]
as the formula for the value. Again, everything works perfectly. Now instead of the above triplets, my list has four entries per line: [item_name]-[item_price]-[item_quantity]-[total_item_price]. And, what is important, when I edit [item_price] or [item_quantity], the [total_item_price] gets automatically reevaluated once I finish editing.
And as the final step, I want to add another calculated control that would display the total price of all items stored at the current location (let's call it "grand total"). A also place that control into the subform (into the "footnote" area this time) and specify the following formula as its value
= SUM([item_price] * [item_quantity])
Now, this works. The total value is calculated correctly each time I change the location in the main form. Also, when I change [item_price] for any item at the current location, the grand total is also updated automatically. However, when I change [item_quantity], the grand total does not update (???). Hitting F9 will make it update. Changing the current location back and forth will update it. But, unfortunately, a mere change to [item_quantity] does not trigger an automatic update.
Does anyone know, what could be wrong here? Why do changes in [item_price] trigger the automatic update of the grand total, while changes in [item_quantity] do not? Intuitively, these fields seem to have the same status (except that the former comes from table B, while the latter comes from table C). Why is the behavior different? How do I make it update automatically?
In your subform's after update event, explicitly recalculate the total price control.
Me.txtTotalPrice.Requery
If you tab through the record and advance to the next record does it still not update. I am thinking that the price is the last field in tab order so when you change it, you tab on to the next record and the change is committed. If I am right then when you edit the quantity, your tab advances you to the price field which is still in the current record so the change is not committed to the table yet. If you advance further through, that should complete the processing.

Determine whether row is selected in MS Access 2007 List Box

I have a situation where I want to associate multiple values from one table with a value from another. I've got my data structured with a many-to-many join table in between, and I'm trying to manage the membership in the join table.
This question is about the UI portion of the process. I think that what I want to do is to present the user with a multi-select List Box control on a form that holds the ID of TableA constant (and, incidentally, hidden). The List would be populated with all the (fairly short list of) rows from TableB (descriptions displayed, IDs in hidden column). On load, I'd select those rows of the list that participate in the M-M join. The user could select additions and/or deselect removals.
What I'm not sure about is how to tell whether or not any given row is selected. I know about the IsSelected collection--if I were just adding, I'd walk that with For Each, but I need to remove any that have been deselected, and I need to not re-add any that already exist. What I'm thinking at this point is walking the whole list, testing each selected value & inserting it if not already present, and testing each un-selected value for possible deletion (hmmm--that's starting to sound needlessly complex....).
What I started out to ask was "how do I tell if row(x) is selected?" I'd still like the answer to that, but I'm open to other suggestions for managing the base problem, as well
In seems that you have a list that you are using to create the selected items. After the user has updated the list box, you can compare .ItemsSelected to the rows of the list that participate in the M-M join. Missing items can be deleted and additional items can be added. A few very rough notes:
For Each itm In Me.AList.ItemsSelected
rsJoinList.Find "ID=" & Me.AList.Column(0, itm)
If rsJoinList.NoMatch Then
'To be added
Else
'To be deleted
End If
Next