Add new record to subform with same ID - vba

I have an Access 2007 DB that tracks tickets. There is a Parent table/form and Child table/form. Parent table houses owner info and Child table houses ticket info. It is a 1 to Many relationship. (Many tickets to 1 owner). There is a sub form that is clickable on the Parent form and opens the Child form. The ID field in the sub form is hyperlinked to the child form. HOWEVER, I am unable to open different records by clicking the sub form. The subform only opens the first record with that ID.

Related

Multiple items form referring to a specific field

I have a multiple item form which takes records from a table:
this edit button I added in Design view , I want to be able to refer to the record which the button is bound to , like really simple task as msgbox this record ID

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 not adding row to table when blank

quick question.
I have a small access db that has 3 tables for memo generation. On the main form you input all of your memo information such as what you purchased, from who, how many, etc. The main ID on the table (and all related tables) is purchase_id.
I created a subform on the main form which is just linked to another table and handles some easy yes/no questions such as "was the purchase over x amount", etc.
However, unless the user clicks into one of the text boxes on the subform, a new row will not generate in the table (even though in the subform I can see the ID linked).
Is there any way to make it so even if a user doesn't click into the subform a row generates in the table with all of the defaults I selected?
Thank you,

Cannot reference Access subform Form object until the first row of parent form has been expanded

When the parent form is opened in datasheet view, I cannot reference the Form object of a subform control until the first row of the parent form has been expanded.
I would like to know a good workaround to this. I need to be able to requery this kind of subform even if the first row of the parent form datasheet has not yet been expanded.
Steps to reproduce the problem:
Create two tables:
CREATE TABLE Parent (
PK Text PRIMARY KEY
);
CREATE TABLE Sub (
PK Text PRIMARY KEY,
FK Text REFERENCES Parent (PK)
);
Insert some data:
INSERT INTO Parent (PK) VALUES ('A');
INSERT INTO Parent (PK) VALUES ('B');
INSERT INTO Sub (PK,FK) VALUES ('AA','A');
INSERT INTO Sub (PK,FK) VALUES ('BB','B');
Create two forms based on these tables and set the default view to Datasheet.
Add Sub form to Parent form and link on sub.FK=parent.PK.
Give the subform container control the name child.
Open the Parent form.
Expand the first row of the datasheet and then collapse it.
Attempt to requery the subform as follows:
Forms!Parent!child.Form.Requery 'This succeeds.
Close and re-open the Parent form.
Expand the second row of the datasheet and then collapse it.
Attempt to requery the subform again using the same code.
This time it fails with the following error:
Run-time error '2455':
You entered an expression that has an invalid reference to the property Form/Report.
From this, I have to conclude that in datasheet view, a subform Form object is not reference-able until the first row of the parent form is expanded.
Not sure if this is correct, but it I think that this is caused by the repeated SubForm control. Each of them is a different Form Object, although they have the same name.
The difference between the first and the second record is the Focus. If you expand the first record, first control of SubForm gets focus. For the second record you have to set focus yourself. If you click on a record of the second records Subform the .Requery works. If you click on first record after this (not expand) your :Requery fails too.
Another thing to try. After expanding first records subform, expand the second one (without setting focus to a control). Now add a record to table Sub with B as FK and then .Requery. You will see that second records subform is not requeried, just the first!
Solution: Requery the control not the form with
Forms!Parent!child.Requery
That affects all records.

VBA Access Force Form Update to show new records added

I have an Access database with two Forms.
Form 1 (Single Form) is designed to browse records from Table 1.
Form 2 (Continuous Form) is designed to browse records from Table 2.
On Form 2, I created an "Import" button, linked to an Event Procedure.
This procedure selects current record from Table 2 and inserts it Into Table 1.
Problem is, the newly inserted record is not shown dynamically on Form 1.
Form 1 needs to be closed and reopened in order for the change to be visible.
Is there a better way to do this "refresh"? From code?