Error 2455 requering another subform (1 Viewer)

Gaztry80

Member
Local time
Today, 22:55
Joined
Aug 13, 2022
Messages
52
Good evening,

I have a form called frmMainTable with two sub forms (frmFirstTable & frmSecondTable), in the subform frmFirstTable I have placed in the on-current event the following code: Forms![frmMainTable]![frmSecondTable].Form.Requery

However, when I open the frmMainTable I get the following error:
Error 2455 while running
The expression contains an invalid reference to the
property Form/Report

Can somebody explain to me why I am getting this error and how to fix it? When I ignore it, everything looks like it works...
I have simulate the problem in the attachment. Thank you for helping me out :)!
 

Attachments

  • demoDatabase.accdb
    1,000 KB · Views: 77

silentwolf

Active member
Local time
Today, 13:55
Joined
Jun 12, 2009
Messages
575
Hi,

first of all you should name your PK's not just Id as ist is difficult to know which Id is for what Table or Form

Secondly nameing the forms should also be a little different and represent that what holds the form

However.

following adjustments will get it working

In the frmFirstTable

Link from Id
Link to Id

frm SecondTable
Link from [frmFirstTable].Form![id]
Link to Id


frmFirstTable

Code:
Private Sub Form_Current()
    Dim ParentDocName As String

    On Error Resume Next
    ParentDocName = Me.Parent.Name

    If Err <> 0 Then
        GoTo Form_Current_Exit
    Else
        On Error GoTo Form_Current_Err
        Me.Parent![frmSecondTable].Requery
    End If

Form_Current_Exit:
    Exit Sub

Form_Current_Err:
    MsgBox Error$
    Resume Form_Current_Exit
End Sub

In the frmMainTable there is no event

just in the frmFirstTable

Hth

Albert
 
Last edited:

MarkK

bit cruncher
Local time
Today, 13:55
Joined
Mar 17, 2004
Messages
8,186
The problem is that your code in the Current event of frmFirstTable is trying to call a method of frmSecondTable, but frmSecondTable isn't open yet.
Yes, you can code around the problem with error handling, but two child tables should not be related to each other if they are both related to the same parent. As such, it should never occur, in a reasonably well designed database, that data changes to one subform should necessitate the requerying of a sibling subform.
So your code fails, and a workaround is shown, but the better solution is to not design your data, and thus not design your user interface, with this kind of 'sideways dependency.'
 

Gaztry80

Member
Local time
Today, 22:55
Joined
Aug 13, 2022
Messages
52
The problem is that your code in the Current event of frmFirstTable is trying to call a method of frmSecondTable, but frmSecondTable isn't open yet.
Yes, you can code around the problem with error handling, but two child tables should not be related to each other if they are both related to the same parent. As such, it should never occur, in a reasonably well designed database, that data changes to one subform should necessitate the requerying of a sibling subform.
So your code fails, and a workaround is shown, but the better solution is to not design your data, and thus not design your user interface, with this kind of 'sideways dependency.'
In my real database, i use this oncurrent event to run an if statement after selecting a row which checks some conditions in frmFirstTable and change the recordsource to a different source in frmSecondTable, afterwards it requeries. Do you have any suggestion or example how I should do it properly? By the way in this case frmFirstTable is related to frmMainTable and frmSecondTable is related to frmFirstTable. So they are not related to the same parent.
 

MarkK

bit cruncher
Local time
Today, 13:55
Joined
Mar 17, 2004
Messages
8,186
If there's a problem you need help with in your real database, I'd be happy to take a look.
 

Users who are viewing this thread

Top Bottom