Others

Open or Create an Access Record from a Subform Link

Maira MehtabMaira Mehtab Nov 22, 2026 868 views

Question details

Open an existing questions record for the current contact or create a new one linked to that contact.

Product
Microsoft Access
Device & OS
not provided
Scenario
A user selects a link on a contacts subform within a company form to view or add questions for the current contact.
Observed behavior
The questions form should display existing records for the selected contact, or start a new record with that contact's ID.
Before you start

Confirm that the contacts subform exposes the current ContactID and that the questions form is bound to an editable source containing a ContactID field. The example below assumes ContactID is numeric and uses CompanyForm, QuestionsForm, and the Questions table as sample names.

Solution 1Recommended

Use a subform click event and pass the contact ID

Use VBA to open matching questions or start a new record, then assign the passed contact ID before insertion.

This example uses a command button on the contacts subform as the link. It passes the current subform record's contact ID to QuestionsForm through OpenArgs, so the new record remains associated with the contact selected when the button was clicked.

If more than one questions record exists for the contact, the form opens filtered to all matching records. Replace the sample table, form, control, and field names with those in your database.

1
Add a subform button

Open the contacts subform in Design View, add a command button, and set its On Click property to [Event Procedure]. Select the build button to open the VBA editor.

2
Open the appropriate questions record

In the button's Click procedure, add: If IsNull(Me.ContactID) Then MsgBox "Select a contact first." Exit Sub End If Dim contactID As Long contactID = CLng(Me.ContactID) If DCount("*", "Questions", "ContactID=" & contactID) > 0 Then DoCmd.OpenForm "QuestionsForm", WhereCondition:="ContactID=" & contactID, OpenArgs:=CStr(contactID) Else DoCmd.OpenForm "QuestionsForm", DataMode:=acFormAdd, OpenArgs:=CStr(contactID) End If

3
Assign the ID before insertion

Open QuestionsForm in Design View. In the form's Before Insert event procedure, add: If Not IsNull(Me.OpenArgs) Then Me.ContactID = CLng(Me.OpenArgs) End If

4
Test both paths

Open CompanyForm in Form View. Select a contact with questions and click the button, then select a contact without questions, click the button, and enter a new record. Check that the saved record has the correct ContactID.

If the questions form is already open: Close QuestionsForm before testing another contact so it opens with the new filter and OpenArgs. Save or complete any edits first.
Free Microsoft Office alternative

Work with Contact Lists in WPS Office

WPS Office is a free, lightweight alternative for everyday documents and spreadsheets, with a familiar interface and Microsoft Office format support that makes migration easier. It does not replace Microsoft Access forms or fix Access VBA.

Organize contact lists in WPS SpreadsheetOpen and edit Microsoft Excel XLSX filesUse a familiar interface for everyday office tasksMove existing Office documents into a lightweight suite
microsoft office alternative - wps office

Frequently Asked Questions

Why does the subform reference use the control name instead of the form name?

The main form contains a subform control that hosts the source form. In Design View, select that container and use its Name property in Forms("CompanyForm").ContactsSubformControl.Form.

What happens if a contact has several questions records?

The recommended OpenForm command filters QuestionsForm by ContactID, so it can display all matching records. Use the form's navigation controls to move between them.

Can I use the direct subform reference if the company form is closed?

No. Forms("CompanyForm") refers to an open form. Keep the company form open or pass the contact ID when opening QuestionsForm, as in the recommended solution.

Why isn't ContactID being saved in the new record?

Check that QuestionsForm is bound to an editable source, its ContactID control is bound to the correct field, and the Before Insert event is set to [Event Procedure]. Also check that the form was opened with a valid numeric contact ID in OpenArgs.