Indepedent Controls/Fields on Multirecord form DB ACCESS - ms-access

I have created a simple inventory management Access DB which in its basic functionality works perfectly.I would like to start to make some polish here and there and I've found the next issue.
I do have a main form for inventory transactions. It has a Header section (with a table of transactions header as a recordsource) and a details section (datasheet type subform into the main form; which means a multiple records form where I can add or remove multiple lines for each header transaction and it is linked to the main form, that works OK).
In this detail/lines subform I have the fields: Category (combobox), Item (combobox) and Quantity (category and item fields are linked to "master categories" table and "master items" table).
I do want to add the following behavior:
When I select a category on category combobox field, the item field updates its selection to show only the items in the selected category.
I can do this easily on a single record form with this code:
Private Sub Category_AfterUpdate()
Me.Item.Requery
End Sub
On the Item field datasource I do have a simple query:
SELECT ID,DESC FROM ARTICLES WHERE ARTICLES.CATEGORY = [FORMS]![SUBFORM].[CATEGORY]
This works flawlessly with a single record form.
However as this is a multiple lines/records form when I select a category on a line, it updates the "Item" selection field for ALL the lines/records, even changing values depending on the selected category.
Is there a way to update controls/fields in an independent way for each record on a datasheet form? Let's say something like:
Private Sub Category_AfterUpdate()
Me.Item(current record).Requery
End Sub
I'm thinking on adding an index to the combobox article field and update only the field on that index but I don't know how to proceed or if it's possible to do that.
Any ideas or workaround to do this?

Related

How do I tie a selected item in a list box to a query (MS Access)?

I have a couple of list boxes on a form that I've created. One of the listboxes has a bunch of supplier names (lst_SupplierName). Upon selecting a supplier name it then auto-populates all Part Numbers under that supplier in another list box (lst_PartNumber).
I would like to take it a step further. So The Part Number listbox is now populating I would like to select a part number and based on that part number be able to create a query that lists all required attributes associated with that part number from the table it's contained in.
Make 2 lists, first one that queries supplier table, second one that queries part table that will use value of first list to query parts only for that supplier. Here is sample tables I created:
And form:
The first list row source is:
SELECT [tblSuplier].[SupID], [tblSuplier].[SupName] FROM tblSuplier ORDER BY [SupName];
Second list row source is:
SELECT tblPart.PartID, tblPart.SupID, tblPart.PartName, tblPart.PartDescr FROM tblPart WHERE (((tblPart.SupID)=[Forms]![frmMain]![lstSup]));
To make second list update, when you select something in first list, you need to add 'after update' event on first list:
Private Sub lstSup_AfterUpdate()
lstPart.Requery
End Sub
Now, you can use after update event to populate different fields on form from parts list the same way - by simply placing value into fields, like txtDescription = lstPart.column(2=3) .
If you have any questions, please let me know.

MS-Access 2013; Change combobox options based on record data in multi-record form

I have a form with multiple records, one per row, being pulled from a table. I have 2 ComboBox controls on each row. The first ComboBox's options are linked to a table of Categories. The second ComboBox's options need to be linked to the subcategories of the first ComboBox.
I have tried having the WHERE statement in the row source at design time, which produced all the subcategories.
I have tried having the WHERE statement, and a requery command, on the change event of the category ComboBox, which produced the subcategories for the last changed category. This was an issues because all the rows would have the same options, instead of the options being based on the category for that record/row.
What I need is for each row to query the subcategory/category mapping table and filter the results based on that row's category selection. Is this possible? If so, how can this be done? I am not afraid of using VBA to get the results I need.
In the On_Current event of the form, you can change the row source of the second combo box dynamically dependant on the value of the column of the first combo box. You probably also need to do it on the after_update event of the first combo box to.
Something like this
Select Case Me.cboCategory
Case "Category 1"
Me.cboSubCategory.RowSource = "qryCat1Subclass"
Case "Category 2"
Me.cboSubCategory.RowSource = "qryCat2Subclass"
Case Else
Me.cboSubCategory.RowSource = ""
End Select
I don't have two combo boxes, just one, but its contents have to be based on a value in another field. This is how I do it.

Update linked fields in access

I have a form that contains a continuous subform that is linked with ID,Date and Shift fields.
ID is not changable in mainform. but date and shift fields can be changed.
The problem is when i change the value of Shift or Date in mainform the corresponding values are not being updated.
EDIT
I made a query to refresh the table of continuos form. It works. But i need to use this code in mainform.
UPDATE SubTable, MainTable SET SubTable.[Date] = [MainTable].[Date], SubTable.[Shift] = [MainTable].[Shift]
WHERE (((SubTable.ID)=[MainTable].[ID]));
I think you need to link the two forms only by a single field. In My scenario I created a field on the sub table called "MainLookup" (Integer). This links to field "ID" on the main form. Changes are made to Date and Shift in the main form. If you were to create a query based on the sub and main you would have only one record of Dates and shifts for each ID. Looking at forms, I created a Main form and a sub form linked ID:MainLookup. The sub form only shows data in the sub table, but the Date and Shift data are intact and as recorded on the main form.

Updating a subform from a list on form

I have a list control on my form. The values of this list come from a query. the Row source of the List is like this:
SELECT tb_lable_Daten.name
FROM tb_lable_Daten;
and Control Source of the list is name
I want if the user change the value of the List(with mouse, key down,...) the value of controls( 3 Texts) in Sub form changes too. The query in Sub form should be:
SELECT XValue, YValue, Wert
FROM tb_DCM_Daten
WHERE (tb_DCM_Daten.name)=name); // It is List value
I put this query on Subforms recordsource but that doesnt work.
Could you please tell me how can I do that?
I know I'm coming in three years late. However for anyone that comes here... The .Requery() is needed but the main issue is that for the Record Source for the field in the subform it should read =[FORMS]![MainForm]![ListField] where mainform = the name of the parent form and listfield = the name of the list field on the parent form. In addition having the .Requery() on update would push the new value to the subform.

Query with data from subform and sum

I have three tables:
Products(ID,Name,Price) /
Customer(ID, Name, Surname)
Buys(ID, ID_customer, ID_product)
I have a form with subform. Subform gets populated with query from Buys table and then connected to Customer(ID) via ID_customer. ID and ID_customer gets hidden on subform.
Then I have two more fields/controls added on subform: Name and aPrice which gets populated via ProductsQuery:
SELECT Products.Name, Products.Price
FROM Products
WHERE (((Products.ID)=[Forms]![PregledKupcev-Form]![NAKUPI-Subform]![ID]));
//ID in this case is control on subform which holds ID of a product
using:
=DLookUp("[Name]";"[ProductsQuery]")
and
=DLookUp("[Price]";"[ProductsQuery]")
So far everything works but it gives me alot of troubles later when i try to sum one control (Price in this case).
Is there any way to do this better?
Then I try to sum up things in aPrice control into PriceSum control on subform's footer:
=Sum([Forms]![PregledKupcev-Form]![NAKUPI-subform]![aPrice])
and transfer it to form with:
=[Forms]![PregledKupcev-Form]![NAKUPI-subform]![PriceSum]
but I get error..
How do I sum up values in Price control on subform?
Pictures:
Let's say that your main form has a text box named txtInvoiceNo in which you display the Invoice Number (or whatever field links your parent table to your child table).
Let's also say that your main form has a text box named txtInvoiceTotal where you want to display the sum of the [Price] values for each child record.
Set the Control Source of the txtInvoiceTotal text box to do a DSum() on the child table (which I've called InvoiceLineItems):
=DSum("[Price]","InvoiceLineItems","InvoiceNo=" & [txtInvoiceNo])
In the After Update event of the subform, add a line to .Requery the parent form's txtInvoiceTotal text box:
Private Sub Form_AfterUpdate()
Me.Parent.txtInvoiceTotal.Requery
End Sub
See if that does the trick for you.