Error with method "Parent"

G

Guest

Hi, can anyone please explain what might have triggered the "parent" error in
general?

In my example, the code below provided by the generosity of Dirk Goldgar
worked great until I developed my db further.

Before error occurs, I have a form (Form1) with two subforms. Both subforms
are based on the SAME table. The data-entry subform (sfSubInput) is in form
view; the list subform (sfSubList) is in table view displaying a list of
already entered records.

The new input entered in data-entry subform is saved and displayed in list
subform after a button (cmdSave) is clicked --and data-entry subform becomes
blank again and ready for another new input.

It's all good up till here. Later I created some other forms using the SAME
table above. Since then, when click cmdSave button, an error message returns:
"Method 'Parent' of Form_sfSubInput' failed"

Why would new forms elsewhere afftect this button? There's no relationship
between new forms and Form1. Also the table has never been altered.
 
A

Al Borges

Hi Sam:

Your line: "Me.Parent!sfSubList.Requery" is kind of weird...

You could use any of these though:

* Me!sfSubList.Requery
* sfSubList.Requery ' (if sfSubList resides in the Parent form truely)
* Forms![Parent]!sfSubList.Requery '(if sfSubList resides on the parent
form)
* Forms![Parent]![Child].form!sfSubList.Requery ' (if sfSubList resides
in a child form)

Regards,
Al
 
D

Dirk Goldgar

Sam Kuo said:
Hi, can anyone please explain what might have triggered the "parent"
error in general?

In my example, the code below provided by the generosity of Dirk
Goldgar worked great until I developed my db further.

Before error occurs, I have a form (Form1) with two subforms. Both
subforms are based on the SAME table. The data-entry subform
(sfSubInput) is in form view; the list subform (sfSubList) is in
table view displaying a list of already entered records.

The new input entered in data-entry subform is saved and displayed in
list subform after a button (cmdSave) is clicked --and data-entry
subform becomes blank again and ready for another new input.


It's all good up till here. Later I created some other forms using
the SAME table above. Since then, when click cmdSave button, an error
message returns: "Method 'Parent' of Form_sfSubInput' failed"

Why would new forms elsewhere afftect this button? There's no
relationship between new forms and Form1. Also the table has never
been altered.

Sam, are you saying that, without your changing *anything* in
sfSubInput, sfSubList, or the main form that contains them, the cmdSave
button on sfSubInput has stopped working? That would be strange indeed,
and lead me to suspect the operation of the Name Autocorrect misfeature.
Go into Tools -> Options..., and on the General tab, make sure that
"Track name AutoCorrect info" is unchecked.

If that is not what you are saying, if this error is occurring on some
other form -- "Form1"? -- let me know.
 
D

Dirk Goldgar

Al Borges said:
Hi Sam:

Your line: "Me.Parent!sfSubList.Requery" is kind of weird...

You could use any of these though:

* Me!sfSubList.Requery
* sfSubList.Requery ' (if sfSubList resides in the Parent form
truely)
* Forms![Parent]!sfSubList.Requery '(if sfSubList resides on the
parent form)
* Forms![Parent]![Child].form!sfSubList.Requery ' (if sfSubList
resides in a child form)

No, you haven't correctly understood the setup, Al. Sam's code is
running on one subform, and requerying another subform that resides on
the same main form. So "Me.Parent!sfSubList.Requery" is not weird at
all. Besides, I gave it to him, so I know it works. :)
 
G

Guest

I have a form (Form1) with two subforms. Both
subforms are based on the SAME table. The data-entry subform
(sfSubInput) is in form view; the list subform (sfSubList) is in
table view displaying a list of already entered records.

The new input entered in data-entry subform is saved and displayed in
list subform after a button (cmdSave) is clicked --and data-entry
subform becomes blank again and ready for another new input.

Thanks for answering my question guys :)
Dirk, I was just trying to simplify my question so it's shorter to read
--but i guess it only makes the question unclear and confuses people more,
sorry

Please bear with me if it sounds long and windy. Here's the full story of my
problem:

The code works fine in a trial db with just this one form (as discussed in
previous thread titled "New record input NOT updated") that I created
specifically to test your code --just so that it's easier for me to spot any
problem that I might have.

Then I implied the same code to a new form (Form1 say) created in an
existing db, along with several other tables, queries, forms, etc already
there. Form1 has the same structure (2 subforms with same RecordSource) as
the trial form aforementioned, except:
1) Instead of just 2 subforms on the main form. I create a TabControl with 4
tabs on the main form. Within each tab there are the 2 subforms -- i.e. In
tab1, sfSubInput1 and sfSubList1 are based on Table1, and the same for tab2-4.
2) the RecordSource of subform-set in each tab is also used in existing forms
elsewhere -- I suspect this is what caused the errors below, but other forms
with same RecordSource work fine still though.

Errors occur in Form1 include:
1) For Tab1: the cmdSave1 button returns "You can't add or change a record
because a related record is required in table 'Table1'" -- because Table1 and
Table2 are linked by a primary key in one of the forms.
2) For Tab 2-4: the cmdSave2 (3 and 4) button returns "parent" error.
3) Each tab also has a cmdDeleteRecord to delet record in sfSubList, but
returns "User-defined type not defined" error.

'--- start of sfSubInput1 module code ---
' (replace all 1's for sfSubInput2-4)

Option Compare Database
Option Explicit
Dim mfSave As Boolean

Private Sub cmdSave1_Click()
If Me.Dirty Then
mfSave = True
Me.Dirty = False
RunCommand acCmdRecordsGoToNew
End If
End Sub

Private Sub Form_AfterUpdate()
Me.Parent!sfSubList1.Requery
End Sub

Private Sub Form_BeforeUpdate(Cancel As Integer)
Cancel = Not mfSave
mfSave = False
End Sub
'--- end of module code ---


'--- start of part of Form1 module code ---
' (repeat for cmdDelete2-4, replace all 1's)

Private Sub cmdDelete1_Click()
Dim response
response = MsgBox("Are you sure to delete this record?", vbYesNo,
"Warning")
If response = vbYes Then
With Me.[sfSubList1].Form.RecordsetClone
.Bookmark = Me.[sfSubList1].Form.Bookmark
.Delete
End With
Me.[sfSubList1].Requery
Else
End If
End Sub
'--- end of module code ---
 
D

Dirk Goldgar

Sam Kuo said:
The code works fine in a trial db with just this one form (as
discussed in previous thread titled "New record input NOT updated")
that I created specifically to test your code --just so that it's
easier for me to spot any problem that I might have.

Then I implied the same code to a new form (Form1 say) created in an
existing db, along with several other tables, queries, forms, etc
already there. Form1 has the same structure (2 subforms with same
RecordSource) as the trial form aforementioned, except:
1) Instead of just 2 subforms on the main form. I create a TabControl
with 4 tabs on the main form. Within each tab there are the 2
subforms -- i.e. In tab1, sfSubInput1 and sfSubList1 are based on
Table1, and the same for tab2-4. 2) the RecordSource of subform-set
in each tab is also used in existing forms elsewhere -- I suspect
this is what caused the errors below, but other forms with same
RecordSource work fine still though.

Errors occur in Form1 include:
1) For Tab1: the cmdSave1 button returns "You can't add or change a
record because a related record is required in table 'Table1'" --
because Table1 and Table2 are linked by a primary key in one of the
forms.

That appears to be a problem of form and table design that I don't have
enough information to solve. If you're trying to save a record in
Table2, and Table2 is in a many-to-one relationship with Table1, then
there must be a record in Table1 with the matching key value that the
Table2 record relates to. I have to guess that either the main form is
not based on Table1, or else it is but you haven't set the Link Master
Fields and Link Child Fields of the subform properly.
2) For Tab 2-4: the cmdSave2 (3 and 4) button returns "parent"
error.

Check the names of the subform controls on the main form. They may not
be what you think they are.
3) Each tab also has a cmdDeleteRecord to delet record in
sfSubList, but returns "User-defined type not defined" error.

I don't see the cause of that error offhand. Which line returns the
error? Again, check the names of the subform controls.
 

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