I'm relatively new to Microsoft Access but have picked it up pretty quickly. I am trying to figure out what sort of VBA or SQL code I could use to force new record creation in subforms once the main table/form is loaded. Let me explain my current form situation:
Main form name: frmUpload, primary key "ID"
Child subform 1: frmIdentifiers, FK "ApplicantID"
Child subform 2: frmFIdentifiers, FK "ApplicantID"
Child subform 3: frmOther, FK "ApplicantID"
These three subforms exist on the main form and record data to tblIdentifiers, tblFIdentifiers and tblOther, respectively. The three subforms have checkboxes only. In most use cases, the user will fill out applicable information on frmUpload and will fill out information in frmIdentifiers, frmFIdentifiers OR frmOther. It is very unlikely that the checkboxes in multiple subforms will be used.
The form links are established properly. If I enter information on the main form and use a checkbox in one of the subforms, the primary/foreign keys populate automatically. That's not a problem.
My question is this: is there any way to force records to write into the other unused tables? For example, if a user only records data to frmUpload/tblUpload and frmOther/tblOther, what could I do to make frmIdentifiers/tblIdentifiers and frmFIdentifiers/tblFIdentifiers both populate "Applicant ID" equal to the primary key of the main form?
Thank you.
Existing workarounds I've tried for this:
- Checkbox with default value to "Yes" that user disables if one of the subforms is not in use. In this way, this forces subform entry and created a new record with proper parent/child links. More inconvenient and less ideal for user interactivity.
- VBA code. Created 3 boolean variables set to False by default, If statements for each child subform. On form entry, the variable is set to true for that subform and if the other subforms have their boolean set to false, a SQL statement ran in VBA would attempt to execute and add the records to the subforms' respective tables. The SQL statement did not work properly, no records were inserted to appropriate tables.
Here's the code:
Dim fCheck As Boolean Dim iCheck As Boolean Dim oCheck As Boolean Private Sub frmIdentifiers_Enter() If fCheck = True And oCheck = True Then iCheck = True ElseIf oCheck = True Or fCheck = True Then iCheck = True Else DoCmd.GoToControl "frmFIdentifiers" DoCmd.GoToRecord , , acNewRec DoCmd.GoToControl "frmOther" DoCmd.GoToRecord , , acNewRec cpiCheck = True End If End Sub The same code is ran for the other two forms, with If statements and booleans switched as needed.



