Reputation: 11
Using MS Access 2010 Macro Builder, how could I enable all controls in 'Details' section of a Form?
I tried to create a public function:
Public Function EnableFrmControls()
Dim ctrl As Control
For Each ctrl In Detail.Controls
If (TypeOf ctrl Is TextBox Or TypeOf ctrl Is ComboBox)
ctrl.Enabled = False
End If
Next
End Function
Then to run this external function from a macro using:
RunCode Function Name: EnableFrmControls()
But didn't work due to compiler error in "For Each ctrl In Detail.Controls" line.
I expected the function would be called from an external function, but this didn't work for me! I get Run-time error '424': Object required when I debug, I get a compiler error in "For Each ctrl In Detail.Controls" line.
Upvotes: 1
Views: 352
Reputation: 3031
You missed form and section targeting:
Public Function EnableFrmControls(nameForm as string)
Dim frmForm as Form
Dim ctrl As Control
Set frmForm = Forms(nameForm)
For Each ctrl In frmForm.Section(acDetail).Controls
If (TypeOf ctrl Is TextBox Or TypeOf ctrl Is ComboBox)
ctrl.Enabled = False
End If
Next
Set frmForm = Nothing
End Function
Upvotes: 1