Adding records to subforms

C

Cathleen

I have a form with two nested subforms, each with a source from a different
table. I would like users to be able to add records but not make edits or
deletions. However, when I set the Allow Edits property of the main form to
No, I can no longer add new records to the subforms. (I can add records to
subfroms when the main form Allow Edits property is set to Yes). How can make
the subforms accept new records without allowing edits to the form?

Thanks so much for any advice I can get!
 
J

John W. Vinson

I have a form with two nested subforms, each with a source from a different
table. I would like users to be able to add records but not make edits or
deletions. However, when I set the Allow Edits property of the main form to
No, I can no longer add new records to the subforms. (I can add records to
subfroms when the main form Allow Edits property is set to Yes). How can make
the subforms accept new records without allowing edits to the form?

Thanks so much for any advice I can get!

You will indeed need to have the mainform's allow edits true to permit any
editing (including additions) on the subforms. What you can do is use the
mainform's Beforeupdate event to cancel any changes, with any warning message
you want (or none at all). Just set the BeforeUpdate event's Cancel argument
to True.
 
K

KenSheridan via AccessMonster.com

First set the Tag property of all controls in the main form you wish to be
read only unless when adding a new record to 'LockMe'. Leave the main form's
AllowEdits property as True. Then in the main form's Current event procedure
try code along these lines:

Dim ctrl as Control

' first move focus to subform if not a new record
If Not Me.RecRecord Then
Me.YourSubformControl.SetFocus
Else
Me.SomeOtherControl.SetFocus
End If

' lock/disable tagged controls if not at new record
For each ctrl in Me.Controls
If ctrl.Tag = "LockMe" Then
ctrl.Locked = Not Me.NewRecord
ctrl.Enabled = Me.NewRecord
End if
Next ctrl

Ken Sheridan
Stafford, England
 

Ask a Question

Want to reply to this thread or ask your own question?

You'll need to choose a username for the site, which only take a couple of moments. After that, you can post your question and our members will help you out.

Ask a Question

Top