To lockdown fields in a form and in the corresponding subform

J

Jack

Hi,
I am trying to open a form. During opening the form I need to lockdown the
fields in the form that has the tag of the fields = "Protected" and also all
the fields of the corresponding subform.
The code I am utilzing is as follows:
To lock all the fields of form and subform
Public Sub LockDown(frm As Form)
Dim ctl As Control
For Each ctl In frm.Controls
Select Case ctl.ControlType
Case acSubform
LockDown (ctl.Form)
Case Else
If ctl.Tag = "Protected" Then
ctl.Locked = True
End If
End Select
Next
End Sub

On the form open event I am calling the function as:LockDown(Me)

However this is giving me a error stating type mismatch. I cannot figure out
where I am going wrong. Any help is appreciated.
 
A

Allen Browne

Which line generates the error? This might give you a clue as to which
object is the wrong type.

Are you sure all controls have a Tag property?
Are you using any ActiveX controls?

It might be a timing problem, particularly if your form has multiple
subforms (and the issue might be version specific.) In theory, Access should
execute the Open event of the subform before the Open event of the main
form. Therefore the subforms should exist when the main form's open event
runs. But there may be cases where this is not the case, so that ctl.Form
does not exist yet.
 

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