How to Hide subform if any fields are dirty

A

AccessNubee

I need to hide a subform if any of the fields on the main form are being
edited.
I can't get that to work

The subform can be shown ONLY after the Save Record button is clicked.
(which is working fine .....Visible=True )

Can anyone help a desparate nubee with a dirty form? ;)
 
J

Jeanette Cunningham

Hi,
a subform has an event called Before Insert.
The before insert event code runs when user enters their cursor in the first
editable control on the subform.
If your code finds that the main form record has not been saved then, you
can cancel the insert.

Private Sub Form_BeforeInsert(Cancel As Integer)
End Sub

As you can see, it has a cancel argument: (Cancel As Integer)
You can check if the parent form is dirty like this:
If Parent.Dirty = True

So we get code like this:

Private Sub Form_BeforeInsert(Cancel As Integer)
If (Parent.Dirty = True) Then
Cancel = True
End If
End Sub


You can also hide the subform from the parent form.
If Me.Dirty = True Then
Me.NameOfSubformControl.Visible = False
Else
Me.NameOfSubformControl.Visible = True
End If

When the main form opens or goes to a new record, your code hides the
subform.
On the parent form's On Load and On Current events put code like this:

Me.NameOfSubformControl.Visible = False


Jeanette Cunningham -- Melbourne Victoria Australia
 

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