Hello everyone
This one has me completely lost. I have a Form used to modify the data of a table (namely t1). Due to a redesign on the DB, some of those fields have been moved to another table (let's call it t2), so now the original form (with its data origin being t1) has a subform with t2 as data origin, so that the related record from t2 can also be edited. This subform allows edition as well as inserts. Both tables are linked through a FK in t1 linked to the PK in t2. The PK in t2 is an auto-numerated PK.
Main form has a combobox linked to the FK in t1 that lists all the desired records from t2 (mainly any record in t2 that is not already linked to a record in t1 plus the one related to the current t1 record (if any)). The user can choose any record from the combobox to assign a different t2 record to the current t1 record, which in turn updates the subform info.
If nothing is selected (that is, if the FK on t1 is null or gets set to null) a button becomes enabled to create a new t2 record, in case it doesn't exist and the user wants to create it without leaving the main form, that does the following:
Code:
Me.cmbbox.Enabled = False
Me.Subfrm.Enabled = True
Me.Subfrm.Visible = True
Me.Subfrm.SetFocus
DoCmd.GoToRecord , , acNewRec
Me.btn.Caption = "Volver a selección"
Basically, it disables the combobox to prevent changing the t1 FK during creation of the new t2 record, enables and shows the subform for table2 (since it's hidden if the combobox has no value) and goes to new record on its recordset. Once it's done, clicking the same button returns to the previous state, and hides the subfrm again, but requeries the combobox so the user can select the newly t2 created record to link it to the current t1 record:
Code:
Me.Cmbox.Requery
Me.Cmbox.Enabled = True
Me.Subfrm.Enabled = False
Me.Subfrm.Visible = False
Me.btn.Caption = "Nueva línea voz"
Now, all of this works well, but the moment I try to type anything on any field of the subform for a new record I get the error message: "You tried to assign the NULL value to a variable that is not a Variant data type." If I skip it and input the required data (some of the fields are unique and required) the record gets added to t2 and appears on the combobox to be assigned to t1. That is, everything works but I can't get rid of the error message nor do I know where it's coming from. Subform for t2 doesn't have any code or events, main form doesn't do anything else with subform aside from enabling/disabling and hiding/showing it. The error message pops up with whatever field I try to alter first on the new record form, be it a text field, numeric field, checkbox....
Subform is on single form view, just in case. No field on t2 has a null value as default, so I'm not sure where this null association is being made.
Any tip on how to tackle it (because right now I'm out of ideas even on how to troubleshoot it) would be appreciated.