Share via

Run-time error 2455: you entered an expression that has an invalid reference to the property Form/Report.

Anonymous
2025-01-20T12:53:05+00:00

Hello Access Experts,

I have a main bound form (frmTest) which has controls (ID, Name, Phone and Address) , two subforms (Test_Sub1 subform), (Test_Sub2 subform) and Command Button (cmdSubmit) (I created this form only for test).

The purpose is to test enabling the button when all fields in main form and subforms are all fulfilled.

I created a public function for that ShowButton() and calling it from every control’s after update event with tag property “Required”

The problem is when I open the main form I get the following error message: “Run-time error 2455: you entered an expression that has an invalid reference to the property Form/Report”.
The line highlighted by the debugger only for subform (Test_Sub2 subform).

The strange thing though is that, when I click “end” on the error, the form opens and behaves correctly and the code works when I test the controls.

Using Access 2019.

Thank in advance for your help.

The function code:

Public Function ShowButton() As Boolean

Dim ctl As Control  
Dim ctl\_sub1 As Control  
Dim ctl\_Sub2 As Control  
  
ShowButton = True  
  
For Each ctl In Forms!frmTest.Controls  
      If ctl.Tag = "Required" Then  
        If Trim(ctl & "") = "" Then  
           ShowButton = False  
      End If  
        End If  
Next ctl  

For Each ctl\_sub1 In Forms!frmTest![Test\_Sub1 subform].Form.Controls  
      If ctl\_sub1.Tag = "Required" Then  
        If Trim(ctl\_sub1 & "") = "" Then  
           ShowButton = False  
      End If  
        End If  
Next ctl\_sub1  
  
For Each ctl\_Sub2 In Forms!frmTest![Test\_Sub2 subform].Form.Controls  
      If ctl\_Sub2.Tag = "Required" Then  
        If Trim(ctl\_Sub2 & "") = "" Then  
           ShowButton = False  
      End If  
        End If  
Next ctl\_Sub2  

Forms!frmTest!cmdSubmit.Enabled = ShowButton  

End Function

Microsoft 365 and Office | Access | For home | Other

Locked Question. This question was migrated from the Microsoft Support Community. You can vote on whether it's helpful, but you can't add comments or replies or follow the question.

0 comments No comments

Answer accepted by question author

  1. Anonymous
    2025-01-21T14:35:27+00:00

    You are unnecessarily duplicating code in the function.  I would recommend that you move the For…Next loop into a separate function, declared as Boolean, into which a reference to each form object is passed as an argument .

    In the calling function, also declared as Boolean, the new function would then be called three times, passing references to the parent form, the first subform, and the second subform respectively.  The return value of the outer function would be set to the value returned by the new function.

    The Enabled property of the cmdSubmit button would then be set to the return value of the calling function, not within it, as you are currently doing.

    Note that in the event of a control being empty, the code in the new function should immediately be terminated and the return value of the function set to False.  Similarly in the event of the new function returning False in the calling function, the calling function's code should immediately be terminated and its return value set to False.

    The default return value of the each function should of course be set to True, as at present.

    If the reference to the second subform is incorrect, then an error would still be expected of course.   The calling function should include an error handler.  As well as trapping any error in the calling function, any error in the new function would be passed back to the calling function's error handler.  As Karl has pointed out, this could include ignoring the error if it is not affecting the functionality.

    1 person found this answer helpful.
    0 comments No comments

Answer accepted by question author

  1. Anonymous
    2025-01-21T11:59:53+00:00

    Hi,

    Are you sure that you only call the function in the AfterUpdate procedures of controls? Not also e.g. in any of the "start" events of the main form, like Load, Open, Current? I ask because it sounds a bit like a timing problem, i.e. a reference to a subform happening before it is loaded.

    If you don't find the cause or find it harmless you could ignore runtime error 2455 in an error handler that your function is missing anyway.

    Servus
    Karl
    ****************
    Access Forever News DevCon
    Access-Entwickler-Konferenz AEK

    1 person found this answer helpful.
    0 comments No comments

7 additional answers

Sort by: Most helpful
  1. George Hepworth 22,765 Reputation points Volunteer Moderator
    2025-01-20T15:00:27+00:00

    One thing to trouble-shoot is whether your references to the subform controls are correct.

    The name of the subform control may or may not be the same as the name of the form in that subform control. Verify that your code is referring to the subform control properly.

    0 comments No comments
  2. Anonymous
    2025-01-20T15:00:05+00:00

    When you get the error message hit the Debug button and it will show you the offending line of code. If that doesn't pinpoint the problem, then report back what line of code throws the error.

    Thanks Scott for your reply,

    here is screenshot from the code:

    0 comments No comments
  3. ScottGem 68,810 Reputation points Volunteer Moderator
    2025-01-20T14:10:43+00:00

    When you get the error message hit the Debug button and it will show you the offending line of code. If that doesn't pinpoint the problem, then report back what line of code throws the error.

    0 comments No comments