Subform locking and preventing deletions

G

Guest

hello,
I have a form/subform setup where on the main form there is a field called
terminate. when this field is set to false, i want the subforms to allow
additions/deletions/updates etc. but when the field is changed to false i do
not want additions/deletions/updates to occure. i have set the subform to
'locked' but this seems to still allow deletions. any suggestions? i know i
could set the enabled property to false, but i would still like the users to
be able to scroll the records in the subform

thanks for any and all help!
ben
 
G

Guest

In your "terminate" text box's OnAfterUpdate( ) event and the form's
OnCurrent( ) event, try:

Call LockSubform

And add this to the form's module:

Private Sub LockSubform()

On Error GoTo ErrHandler

Dim fLocked As Boolean

If (UCase$(Nz(Me!txtTerminate.Value, "FALSE")) = "FALSE") Then
fLocked = True
ElseIf (UCase$(Nz(Me!txtTerminate.Value, "TRUE")) = "TRUE") Then
fLocked = False
End If

Me!subfrmCtrl.Form.AllowAdditions = fLocked
Me!subfrmCtrl.Form.AllowEditing = fLocked
Me!subfrmCtrl.Form.AllowDeletions = fLocked

Exit Sub

ErrHandler:

MsgBox "Error in LockSubform( ) in" & vbCrLf & _
Me.Name & " form." & vbCrLf & vbCrLf & _
"Error #" & Err.Number & vbCrLf & vbCrLf & Err.Description
Err.Clear

End Sub ' LockSubform( )

.. . . where txtTerminate is the name of the text box with True/False text,
and subfrmCtrl is the name of the subform control (_not_ the subform name).
Check that AllowEditing is turned off when appropriate in your version of
Access. No matter which state this Boolean value is in with my version, the
subform is always editable. If yours is too, then you'll have to lock the
subform control, as you have already done.

HTH.
Gunny

See http://www.QBuilt.com for all your database needs.
See http://www.Access.QBuilt.com for Microsoft Access tips.

(Please remove ZERO_SPAM from my reply E-mail address so that a message will
be forwarded to me.)
- - -
If my answer has helped you, please sign in and answer yes to the question
"Did this post answer your question?" at the bottom of the message, which
adds your question and the answers to the database of answers. Remember that
questions answered the quickest are often from those who have a history of
rewarding the contributors who have taken the time to answer questions
correctly.
 

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