Nested subform - how to hide if no valid parent selection

M

Meg Russell

Hi group

I have a nested subform which I would like to hide if it has no valid
selection on its parent.

The structure goes
Main form - customerID
subform1 - orderID linked by CustomerID
subform2 - orderProductID linked by orderID (text field on main
form linked to subform1)

subform2 is always visible, but I would like to hide it until there is a
valid record selected or entered on subform1

I have tried various triggers on the OnCurrent an AfterInsert events but
have had no success.

any ideas?
thanks!
 
A

Allen Browne

You could use the Current event procedure of subform1. Test NewRecord, and
set the Visible property of the subform control (the one that contains
subform2.) Include error handling. Use the AfterInsert event procedure of
subform1 as well. You may need to be aware that if the new record was saved
because the user tabbed out of the last text box in the tab order, that the
subform will go to a new record again, in which place the subsubform will go
invisible again.

Personally, I think it's confusing for users if things just disappear on
them. It might be better to leave the subform visible, but warn the user
that the need to fill in the parent form's record first. You can do that
really easily by using its BeforeInsert event. Access fires this event with
the first keystroke the user enters into a new record. Just cancel the event
if the parent form is at a new record.

This kind of thing:

Private Sub Form_BeforeInsert(Cancel As Integer)
If Me.Parent.NewRecord Then
Cancel = True
MsgBox "Fill in the parent form record first."
End If
End Sub
 
R

Rod Plastow

Hi Allen,

How about disabling the subform control until there is appropriate data in
the main form?

Regards,

Rod
 
M

Meg Russell

Thanks Allen - that is exactly the kind of advice I was after!
This community is a wonderful thing!
 

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