I have created a main form and subform and want to prevent Access from adding
new data into the subform until I've entered key data, like a Primary Key
(AutoNumber), into the main form. I have a main form with Writeup information
and a subform with Officer information. I don't want new Officer data entered
until there's an associated Writeup record. It's my understanding, when you
enforce referential integrity between the underlying tables, Access prevents
you from entering orphan records. However, it only prevents this AFTER you've
typed in the data. This is very frustrating. What I would like to accomplish
is to prevent additions to the subform entirely, until you've entered the key
value into the main form. I have tried to accomplish this by taking advantage
of the form's AllowAdditions property. Toggle this property on and off
depending on the null state of the key field. Using my Writeup/Officer
example, in the main form's Current event procedure, I've entered the
following code statement
[sfrWriteUpStaffInvovled].AllowAdditions = Not IsNull([WriteupID])
When the CustomerID field is null, this statement evaluates as follows
[sfrWriteUpStaffInvovled].AllowAdditions = Not IsNull(Null)
[sfrWriteUpStaffInvovled].AllowAdditions = Not True
[sfrWriteUpStaffInvovled].AllowAdditions = False
Problem: I get a complie error "Method or Data Member not found".
Can someone give me some advise as to what I have done wrong.
Kevin
Jeanette Cunningham - 22 May 2008 09:28 GMT
Kevin,
forms have an event called Before Insert. It has a cancel argument
available.
So on the subform you can put code in its before insert event to check if
certain fields on the parent form have been filled in.
If those fields are empty, your code can set Cancel = True, with a msgbox to
tell users about the problem.
Users won't be able to enter data in the subform if the before insert event
is cancelled.
Jeanette Cunningham -- Melbourne Victoria Australia
>I have created a main form and subform and want to prevent Access from
>adding
[quoted text clipped - 30 lines]
> Can someone give me some advise as to what I have done wrong.
> Kevin
poucedeleon - 27 May 2008 13:24 GMT
Thanks Jeanette I ended using the following code on the Enter Event and it
works great.
Private Sub sfrWriteUpInmates_Enter()
'If "New Record" then Fill out writeup info before selecting Inmate name.
If IsNull(Me![WriteUpID]) Then
MsgBox "Enter Writeup information before entering Inmate names."
DoCmd.GoToControl "[DateNumberIssued]"
End If
End Sub
>Kevin,
>forms have an event called Before Insert. It has a cancel argument
[quoted text clipped - 13 lines]
>> Can someone give me some advise as to what I have done wrong.
>> Kevin