Hi,

I have a form with a subform that also has a subform. Both subforms are usually in datasheet mode.

On the main form I have a toggle button the user must press before changes to the form and subforms can be made. I have a function that is called to block/enable access to the controls. This function loops through the controls on a form, and if a control is a subform, it calls itself for the subform (recursion).

Problem is that this seems to fail for the second subform: "Error 2455: You entered an expression that has an invalid reference to the property Form/Report." Using the debugger, I see that the (subform) control on the second recursion is full of invalid references to properties.

What goes?

My enable / disable function is something like this:

Public Sub AllowFormEdits(pForm As Form, bAllowEdit As Boolean)
Const conFormView = 1
Const conDataSheet = 2
Dim ctl As Control

Select Case pForm.CurrentView
Case conFormView
Case conDataSheet
' Change the background for datasheet mode
If bAllowEdit = True Then
pForm.DatasheetBackColor = 16777215 ' White
Else
pForm.DatasheetBackColor = 12632256 ' Grey
End If
End Select

With pForm
' Loop all controls on form
For Each ctl In .Controls
If TypeOf ctl Is SubForm Then
Call AllowFormEdits(ctl.Form, bAllowEdit)

ctl.Form.AllowAdditions = bAllowEdit
ctl.Form.AllowEdits = bAllowEdit
Else
Call AllowControlEdit(ctl, bAllowEdit) ' Changes color etc
End If
Next
End With
End Sub

Thanks,
Onno Willems