subform resetting settings - followup

G

Guest

Hi
I posted a question last week (12 may) about a subform being reset when I
flick between parent forms. One parent form allows editing and not filtering,
one allows filtering and not editing and another allows adding new records.
(this is to help the user distinguish between modes). However, with the
change in properties for the parent form, the subform also changes
properties, so when I filter to find a particular record then go to the
editing form, the properties for the sub form have changed so as not to allow
editing.
I had a reply last week to set the On Open event to check which form the
subform is being opened in.
the code is as follows:

Private Sub Form_Open(Cancel As Integer)
Select Case Me.Parent
Case "candidate details find"
Me.AllowEdits = False
Me.AllowDeletions = False
Me.AllowAdditions = False
Case "candidate details edit"
Me.AllowEdits = True
Me.AllowDeletions = False
Me.AllowAdditions = False
Case "candidate details add"
Me.AllowEdits = True
Me.AllowDeletions = False
Me.AllowAdditions = True
Case Else
Exit Sub
End Select

End Sub

However now when i try to open the subform I get an error and the debugger
says
" the expression you entered has an invalid reference to the parent property"
How do I correct this?
 
N

Nikos Yannacopoulos

Hi Lynn,

I believe it was me who actually gave you this code, and looking at it
again I just realized there's a mistake for which I apologize: The
Select Case line should be:

Select Case Me.Parent.Name

That will fix its behaviour when opened as a subform, but that's
different to the code not working when opening the form on its own; in
that case there is no parent form, thus the eror. If you also need to
open the form on it own, then you need to modify the code as follows, to
skip the Select Case part when opened independently:

Private Sub Form_Open(Cancel As Integer)
On Error GoTo No_Parent
Select Case Me.Parent
On Error GoTo 0
Case "candidate details find"
Me.AllowEdits = False
Me.AllowDeletions = False
Me.AllowAdditions = False
Case "candidate details edit"
Me.AllowEdits = True
Me.AllowDeletions = False
Me.AllowAdditions = False
Case "candidate details add"
Me.AllowEdits = True
Me.AllowDeletions = False
Me.AllowAdditions = True
Case Else
Exit Sub
End Select
No_Parent:
End Sub

HTH,
Nikos
 

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

Similar Threads


Top