Update linked fields in access - ms-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.

Related

Indepedent Controls/Fields on Multirecord form DB 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?

How do I reference a autonumber field in access vb and be able to use it for a calculation

I have a auto number in a table that serves the purpose of a order id. I made a form to input line items for this order id into that table . I want a function that would allow me to click my "add to order button" and it would continue to use the same order id for every record until I complete the order. I tried the following in the on_click sub for my add record button. me.txt_Orderid = me.txt_OrderId - 1 but naturally that doesn't work. I am fairly new to access so the access vba is tripping me up. Ideas?
You should not be using AutoNumber on a field if you are wanting to multiple records of it. Instead create a new field and use that for your orderid. When you create new orders youll want to grab the max of that field, then add one. see below...
On Error Resume Next
DoCmd.GoToRecord , "", acNewRec
If (MacroError <> 0) Then
Beep
MsgBox MacroError.Description, vbOKOnly, ""
End If
'This is where you assign new order numbers.
Me.OrderIDFormControl = (DMax("OrderIDField", "OrderTable") + 1)
This will acheive the same result, but is better. And you can have duplicates of it.
Once you fix your ID, then every time you add a OrderLine Item you just grab the id of the order, and assign it to the new records.
There would be two tables tblOrder which will be master table for Orders. You can use OrderID as autonumber in this table. And second table would be tblOrderItems , this would be the detail table having duplicate values of OrderID for more than one Order Items.
Create a form frmOrder that binds to tblOrder, create another form that binds to tblOderItem. Now open the Order form in design mode, press F11 to see other forms in database, drag and drop frmOrderItem being create. Now this form will be a subform inside main Order form.
The sub-form property, set Master field, Child field property . You will be asked to set related fields, it would be OrderID from both the tables/forms.
You can use this form without need to code to get OrderID when inserting data to tblOrderItem. Access picks up value for you and adds.
Still if you want to have OrderID in your code for any reason or coding a unbound form/subform. You can get the value of OrderID from frmOrder form. when referring this tbOrderID text box control anywhere in the code of frmOrder, you can just use tbOrderID.value , but if you want to refer the text box in subform, remember to refer it with form name or get from Parent property of sub form for e.g. Forms![frmOrder].tbOrderID.value in case you want to use with Parent e.g. Me.Parent.form.tbOrderID.value

Access VBA - Button on Report to show additional information

I have a report called 'Expenditures' that shows various information about each record (date, amount, type, etc.). Each record also has a 'Notes' field.
I want to add a button on each line of the report (I've done that part) that will show the Notes for the selected record. I'm not sure if this would just be running a query, then displaying it, or something else.
All I have right now is a query that shows the Notes field, but when you click the button, it shows the Notes field for all the records since I don't have any criteria yet.
Is this possible? If so, I would appreciate any help! Thanks in advance.
Typically reports in access are not 'interactive' (unless you view them in "Report" view). For example, the button will not be visible on "print preview".
I suggest you add a field to your table that controls the visibility of the field (ShowNotes = Yes/No). That checkbox would be added to the form where you maintain the data. When running the report you would then add code to the "On Format" event for the details section.
Private Sub Detail_Format(Cancel As Integer, FormatCount As Integer)
Me.Notes.Visible = Me.[ShowNotes].Value
End Sub
Or, if you are going to the trouble of adding the field to the table, you could adjust your query below the report to show values in the "Notes" field only if the check-box is checked. (a "no code" solution).
I had the same issue with a report 'Invoice List' that displays the summary info about all invoices, and I wanted to have a button on each line to open the report 'Invoice' that displays the full details of just that invoice. In the event properties of the button I added an OnClick event (using the macro builder). This event is OpenReport 'Invoice' and includes a filter with the following condition;
[Invoice_Data]![Invoice_No]=[Reports].[Invoice List].[Invoice_List_Invoice_No].[Value]
The report 'Invoice' has got a query added to its Record Source (Data Tab) property called 'Invoice_Data' which pulls the invoice data from the various tables, the above filter condition then just tells it which individual Invoice No to use when running this query.

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.