Before Update Event or After Update Event (MS Access 2013) - forms

I develop small database which gets bigger every day and I've got a situation with Before Update Event on one field.
Let's say I have main form which has subform based on the table (PONSt). The subform has one specific field (PONSt_PDV) which data depends on the other table (APP_PDV). When user updates that field (PONSt_PDV) directly in combo box, Before Update events is triggered and some calculations are done. That works perfectly!
The second situation (which is the reason for this question) is when user double clicks that combo box to open pop up form which contains the data from the other table (APP_PDV). In that pop up form user can edit, add or delete it's data and everything works great. There is a button on that pop up form which is used to get data (ID) from that table (APP_PDV), store it to the first table's field (PONSt_PDV), close the pop up form and get back to the first form (sub form on the first form, to be exact). After that, I want to recalculate other fields (in the first table PONSt) depending on the change in field (PONSt_PDV), but Before Update (or After Update) event in that case doesn't trigger at all.
What I'm doing wrong? Is there something that I can't see? Thanks!

Related

Pop-up form that creates record that links 1:1 to main form

I have a pop-up form that opens using a button on the main form in a MS Access database. The pop-up form creates a new record (in a separate table) that needs to link to the current record in the main form. How do I set this up properly?
The two forms (frmMain, frmWB) are based on 2 separate tables (tblMain and tblWB). The records have a 1:1 relationship (each main record can only have one WB1 record).
The main form (frmMain) has the primary key [ID]
The pop-up from (frmWB) has the primary key [WBID] (autonumber) and [MainID] (number).
Data entry personnel will enter the main info first (this will have to be required to avoid orphans), then click a button that saves the main record and opens the pop-up form to add the detailed info. When done, they click the close button which saves the pop-up record, closes the pop-up, and returns to the main form (which stayed open in behind). Navigation has been disabled in the pop-up and it is set to cycle the current record.
I have tried linking using the primary IDs for the two tables, but that doesn't seem to reliably link the correct ID numbers when adding a new record in the pop-up. I tried using subforms, but had problems if the navigation or 'new record' buttons on the main form were accidentally hit when entering data in the subform - that created records in tblWB that had the wrong ID numbers.
If frmWB is opened modal, so that the current record of frmMain can't be changed while the popup is open, you would have this in the BeforeInsert event procedure of frmWB:
Private Sub Form_BeforeInsert(Cancel As Integer)
Me!MainID = Forms!frmMain!ID
End Sub
This automatically assigns the tblMain ID to the newly created tblWB record.
MainID should be an invisible textbox on frmWB, bound to the table field MainID. While debugging you can make it visible, but it should be locked.
If frmWB isn't modal, I would use OpenArgs to pass the ID from frmMain to frmWB. And then use that in Form_BeforeInsert instead of Forms!frmMain!ID
Contrary to Andre's comment, the usual way is to create a relationship between the two tables, enforce referential integrity and use cascading updates.
While this article is specific to Office 2003, the concept is the same for all versions of Access. If you do this, the popup will automatically create a new record linked to the main form's record.

Combobox governing subform possibly updating tables

I have a form, the form is bound to a query which returns only one field. On that form is one combo box, bound to the field from the query, a subform object and some other unimportant stuff. The Master-Child relationship between the Form and Subform is set to that same field. The intent is that dropping down the combo box allows me to add information on the subform pertaining to that record in the combobox (it's a list of classes in a school, for context). This is done through a form and subform as I have various different tasks that need to be done for each class - the intent is to be able to select a class on the main form and then use command buttons on it to select which subform is opened depending on which task I wish to perform.
However, the Combo box appears to be trying to update a table - I'm not sure which one as the error message isn't specific:
The changes you requested to the table were not successful because
they would create duplicate values in the index, primary key or
relationship. Change the data in the field or fields that contain
duplicate data, remove the index or redefine the index to allow
duplicate values and try again
appears if I select any value other than the first one from the combo box and then click in the first text box on the subform. However, I can click in the subform with the first entry in the combo box selected and add data successfully, I've checked and it is appearing in the underlying tables.
It seems to me, as a relative novice in Access, that the combo box is attempting to update the underlying data source when it is changed, though it has no macros. I would assume there are items in the properties of the form or the combobox that prevent that from happening but I can't find them. That is just a guess as to what's happening, though, and I could be wrong.
It's possible that this is related to this question but I could be mistaken there as well. Regardless, the Form shouldn't be able to update/edit/add records but if I set Allow Edits in its properties to "No" I am unable to actually select a value from the combobox - I have set the other "Allow" properties to "No" without a problem.
If you change anything in the main form and then click on the subform then Access will try to save the data in the main form automatically. Maybe you can try to temporally exchange the combo box with a text field for testing. That should help you to clarify the problem.

Move to next record recordset after query in access vba

This is my first question but I have to say that is not the first time that I've used the site. One more thing, sorry for my english...
I'm working on a project in Access 2007 with a lot of VBA code and a lot of forms to the front end. In the forms I've included record navigation buttons for the user to move between the different records of the table (next, previous, etc).
However, I have a problem I do not know how to fix. Imagine that the user enters a form. Naturally, the form shows the 1st record contained in the table. In the form, the user can search a record and go to a specified record.
After getting that record, the user presses the button to display the next record. However, instead of going to the next, it goes to the record after the 1st. In other words, the form goes to the 2nd record.
I guess it's because recordset of the form hasn't been updated, so when the user presses the next button (actually I am doing a docmd.gotorecord acNext), it goes to the next record that is in the table (the 2nd record).
I tried updating the recordset after making the query though the form recordsource method, but nevertheless it continues to go wrong ...
What would be the most practical solution?
Thanks!
Your issue comes from the fact that when you set the filter to false, you actually re-set the entire form.
To get around this, you can try this for your search command:
DoCmd.OpenForm "Customers"
' This assumes that you've got a control on the customers form named ID which has the IDs in it
DoCmd.GoToControl "ID"
DoCmd.FindRecord Me.search_customers_subform.Form.ID
And when clicking next, all you need now is:
DoCmd.GoToRecord , , acNext
The filter doesn't exist anymore.
Hope this works for you. I don't have Access on me right now so this code is mainly from memory, if there's any problems, feel free to ask.

Access Form won't accept input in text boxes

So I have a form in Access.![acessform1][1]
Here are form properties
I got this database and have been making adjustments to the other forms. I gave the database back to the user and they reported an issue that this form is not acting properly, and the add order record function is not working anymore.
There's an Add Order Record button on the right side of the form that would usually add the record if the user manually entered input into some of the boxes. The old form you would have control of the values 1/0 for yes/no. You can enter text into the notes boxes.
This functionality doesn't work anymore, and I can't seem to figure out why. The form is identical to the original and no adjustments have been made except to the table that it pulls data from.
So the symptoms are:
User input is not accepted in text boxes.
The find CP functionality works with the drop down and reflects the records accurately but I cannot update the fields.
Also, the fields CP_Ref and Invoice date don't let me enter data anymore.
Also the Add Order Record was giving me an error that The it could not find the record specified, but I since copied the original form back into place and that error went away.
I think functionality wise this button should save the record after a field is updated and should add a new record.
Seems like all the controls are locked on the page.
Here is the query that pulls the data when I click the button that takes me to the Order form.
SELECT DISTINCTROW CPOrders.Cust, Customer.NAME, CPOrders.CP_Ref, CPOrders.Slsman,
CPOrders.Date_opn, CPOrders.CPSmall, CPOrders.InvIssu, CPOrders.InvNo,
CPOrders.InvDate, CPOrders.DueDate, CPOrders.ETADate, CPOrders.Closed,
CPOrders.Cust, CPOrders.Name, CPOrders.BuyerRef, CPOrders.ToCity,
CPOrders.ToState, CPOrders.ToCtry, CPOrders.ToPort, CPOrders.Supplier,
CPOrders.Origin, CPOrders.Product, CPOrders.GradeType, CPOrders.NoUnits,
CPOrders.Pkg, CPOrders.Qty, CPOrders.TotSale, CPOrders.TotCost,
CPOrders.GrMargin, CPOrders.[Sale$/Unit], CPOrders.[Cost$/Unit],
CPOrders.OceanCost, CPOrders.OceanNotes, CPOrders.BLadingDate,
CPOrders.USAPort, CPOrders.FOBCost, CPOrders.FASExportVal,
CPOrders.InlandFrt, CPOrders.CommodCode, CPOrders.Notes,
CPOrders.ProjCust, CPOrders.ProjValue, CPOrders.ContainerNumber,
CPOrders.Vessel, Customer.TERMS
FROM Customer INNER JOIN CPOrders ON Customer.[CUST_#] = CPOrders.Cust
ORDER BY CPOrders.CP_Ref;
I ended up checking several locations for the answer to this.
What it ended up being was a primary key issue.
Essentially when I got the updated database I put them into new tables, effectively destroying the dependencies, relationships, and established keys.
I reverted back to the old tables and found out the form worked properly.
The issue ultimately was that the primary keys were not defined as needed for the table to be updated.

ms access Add, Edit, Delete Items through an Access form

I'm not real familiar with inputting data through forms. Up until now I've just been handling the data from the table. However, now I have a table with two pieces of information:
Group ID
Each ID is in a group, not all IDs are represented in the table (ie there is another table with a complete list of IDs...many to one), and multiple IDs can be associated with the same group.
I want to make a form that allows the user to add a new ID/group row, edit an existing ID's "Group," and delete an existing Row. I want the user to see the changes he/she has made. I think there's a way to show a snapshot of the table as part of the form? How do I do all this?
Have you tried a continuous form? You can use a combo to display additional information for each control/field, if that is required.
EDIT re Comment
From your comments and original post, it seems that what may suit is a main form and subform. The subform can be set to prevent editing - it will display the existing groups. The main form will have your combos and buttons.
As to the various types of form, look at the Views Allowed property for the form, you will find:
Single Form (suitable for main form)
Continuous Form (suitable for subform)
Datasheet
Link one table (or query) to the main form and your second table (or query) to a sub form. Drag your sub form onto the main form. Tie the two forms together in properties (sub form) under link master fields and link child fields add the key ID.