That will probably occur if you are entering a new record in the parent form
as the subform's Current event procedure will execute, but before a value has
been passed to the job number foreign key in the subform's underlying
recordset via the linking mechanism between the parent and subform.
You could cater for that by removing the code from the subform's Current
event procedure and putting code in the parent form's AfterInsert event
procedure to set the value of whatever control in the subform has the default
value to itself. The subform will at this stage be at a new record, so this
will Dirty the new record so that it is then saved. The code would be
something like this:
Dim frm as Form
Set frm = Me.YourSubformControl.Form
frm.[YourControl] = frm.[YourControl]
In the above YourSubformControl is the control in the parent form's Controls
collection which houses the subform, NOT the control on the subform.
However that will only handle situations when a new record is inserted in the
parent form, not when a new record is inserted in the subform where the
record in the parent form already exists. Also it automatically insert a row
into the subform's underlying recordset whether you want this or not. If
the latter is acceptable, then this might be a viable solution as it would
mean that for each parent record the subform would have one row automatically
inserted with the default value. The automatic insertion of further rows
with the same default value would violate the key of the subform's underlying
recordset, so even if it was possible to engineer this, it would result in a
data error.
Ken Sheridan
Stafford, England
So that works, however in my main form, I have fields that can't be null. As
soon as I enter a value in the main form, it starts giving multiple error
messages that index or primary key can't contain null values. I guess it's in
a way jumping to the sub-form and making the auto entry before I've completed
the main form's entries. Any work-around for this? Thanks!
The fact that you see the default value in the control does not mean that a
new record has been initiated. The DefaultValue property does not assign a
[quoted text clipped - 23 lines]
up the default value otherwise. Any way to change that so it picks up the
default value even if no change is made? Thanks