Error updating field in ms access 2007 - ms-access-2007

I have a form on which there are two subforms.In the afterUpdate() event of combobox of subform1 I want a combobox of subform to get updated with the same value and vice versa.Subform2 depends upon subform2 for its field called ID.As in if I create a new record on subform1 then the subform2 displays data based on records in subform1.New entries can be made in subform1 and modification in the data on subform2 can be made for the records in subform1.This is because subform1 brings data from the base table and subform2 gets related data from some other related tables also.
Everything runs fine if Ihave to update the comboboxes in the 2 subforms for an existing record.However,if I add a new record in subform1,then it throws error "you cannot assign a value to this object" in the afterupdate event of the combobox of subform1.Now if I navigate to subform2 and come back to subform1 and change the value of combobox, it gets updated and throws no error.
The comboboxes in both the forms have same rowsource.
Please suggest me some methods which I can use to avoid this problem.

Related

Is there an On Click Event when the user selects a row in a subform?

I have a Microsoft Access application. The form frmCustomersOrdersProducts depicts Customers and their Orders. Therefore, the form contains two subforms subfrmCustomerList and subfrmOrderList. These two subforms are automatically created based on queries.
I want to show the orders for a particular customer when selecting a customer on the subform.
Unfortunately the subform provides only two events On Enter or On Exit. The Detail section of the form has an On Click event, but the method is not triggered when selecting a row.
What works is the On Click Event on certain fields / columns, for now I use the click event when the ID column is selected. But using the On Click event for every single column does seem very cumbersome?
Is there an on-click / on-select event for the whole row?
You need to work in the subform(s), not the subform controls in the main form.
There you have the full set of events, including On Current.
To requery the order subform after selecting a customer record, you could have something like this in the customers form:
Private Sub Form_Current()
' subfrmOrderList is the name of the subform control (!) on the main form
Me.Parent.subfrmOrderList.Form.Requery
End Sub
See here for more examples how to address subforms and their controls:
Forms: Refer to Form and Subform properties and controls

MS Access Subform adding multiple rows

I have a form that I use for memo generation which I just added a new subform to which handles contract info. It is a small table which only has the PurchaseID (linked to the main table) and then the contract fields shown as text boxes/combo boxes.
My Issue: Originally what was happening was when a user didn't click into the sub-form shown, no row would be created in the Contract table. If you look at the picture, when the form loads the "PurchaseID" field is populated because it's an autonum linked to the main table. However even though that field is populated, if a user doesn't physically click into the sub-form, no row gets created. I just want the blank row with the default options to be added to the table.
My attempt to fix it:
What I tried doing to fix this is on the event "On Current", I wrote 1 line of code that just sets the value of the combo box to a value. I think this sets the sub-form as a focus and it does end up creating the record. The problem is, now whenever the form loads, it initially tries to add a blank row with the ID of 0 to the Contract table, essentially making a duplicate blank row every time the form opens. I think the reason is because the "On Current" event is happening before the "PurchaseID" field is linking to the main table, resulting in a PurchaseID of "0" continuing to duplicate when the form is opened.
What I need:
Looking at the picture below. How do I make it so when a user does not click in that subform box when going through everything, a new record is added to the sub-form table with the default values selected (procurement/notrequired/etc.).
Picture of form. Sub-form that has issue is circled.

Trying to open another form in Access based on a field in the current form

I have a form that's just a list of descriptions (desc.) of other forms. Right now, when you click on a desc., the appropriate form opens; but it's done through a series of if statements in a macro. This isn't going to scale well once more forms are created.
I have a table that has the desc. and the form that is supposed to go to. I want to write a script that uses this table to open the new form based on the desc. clicked, but not using if statements. The end goal is to be able to just add a row to the table for any future forms that are created without making changes to the script or form. Is there a way to do this?
Use a combo box whose row source is a query which selects the form description and name fields from your table.
The combo will have 2 columns. You can set the width of the form name column to zero if you want to present only the form descriptions. If you make the form name column the combo's bound column, you can reference it conveniently in a DoCmd.OpenForm statement. For example, you could have a command button whose click event opens the form which is currently selected in the combo ...
DoCmd.OpenForm Me.YourComboName.Value

How to get event when moving recordsets Access form?

I have an Access form which uses SQL to populate dropdowns. This SQL is using a value in the form for a combo box cb_Priority, such as:
SELECT ProjectPriorities.ProjectPriority FROM ProjectPriorities WHERE (((ProjectPriorities.[mType])=[Forms]![testQuery]![mType].value));
In other words, I am using the current recordset to populate a dropdown on the form.
I would like to call the following when a user moves between records (ie which one is currently displayed in the form).
Form_testQuery.cb_Priority.Requery
This repopulates the form dropdown correctly.
However, I cannot find the event for what I would imagine to be something like
Form_RecordsetChange()
Form_RecordsMove()
How I trigger this .Requery method to allow it to run each time the userform updates to a different record?
The event you are looking for is: Form_Current.

Filtering subform using linkchildfield?

I need to filter a subform using a value in a combobox from the mainform.The value in the combobox is string(a sentence of a line or two)This value is called "Descr" in the select query of the subform and the name of combobox in the parent form is "cboOverdueDescr".
I have put the following code in the AfterUpdate event of the combobox.
LinkChildFields="Descr"
LinkMasterFields="cboOverdueDescr"
The problem is that the subform shows no record when I select any value in the combobox.However, the subform gets filtered accordingly when I do it the same way with another combobox which displays values like "B13-1000"
Even if your combo has a column called Descr, your form does not know that, all it knows is the number of columns, however, you can use a combobox as the link master field for a subform, the filter will use the value of the bound column. Just set the link master field to the name of the combo, there is no need to use an event.