View Full Version : Repost still looking for help on subforms


Chucklinn
06-04-2001, 11:10 AM
I have some subforms that I am trying to unlock when I click on a edit button on the main tabbed form.
I have tried the following code
Private Sub EditRecord_Click()
Dim ctl As Control
Me.AllowEdits = True ' this opens the main forms edit property

For Each ctl In Me.Controls
If ctl.ControlType = acSubform Then
ctl.AllowEdits = True ' THIS IS WHERE I GET THE ERROR MESSAGE
End If
Next ctl

the error message is the object doesn't suport this property or method.
I have tried writing functions to get around this and nothing seems to work. any help will be appreciated

Jack Cowley
06-04-2001, 01:04 PM
Me.AllowEdits = True 'this will allow edits in Main form
Me.SubformName.Locked = False 'This will allow you access to the subform

A subform is just another control on a form so setting its Locked property to True or False locks or unlocks access to the subform. I would suggest that you just set the subforms Locked property to Yes and then unlock it when you allow edits in the main form....

Angello Pimental
06-05-2001, 04:17 AM
Try this....

Set the following properties for the subform:
Enabled = No
Locked = Yes
Tag = unlockme

The edit button will have the following properties:

Name: subform_unlock
Caption: UNLOCK
In the on_click put this code:

Private Sub subform_unlock_Click()

Dim frmMyForm As Form
Dim ctlMyCtls As Control
Set frmMyForm = Forms!Renewal ***Substitute Renewal for the name of your form****

If subform_unlock.Caption = "UNLOCK" Then
For Each ctlMyCtls In frmMyForm.Controls
If ctlMyCtls.Tag = "unlockme" Then
ctlMyCtls.Visible = True
ctlMyCtls.Enabled = True
ctlMyCtls.Locked = False
subform_unlock.Caption = "LOCK"
Me.Refresh
End If
Next ctlMyCtls
Else
For Each ctlMyCtls In frmMyForm.Controls
If ctlMyCtls.Tag = "unlockme" Then
ctlMyCtls.Enabled = False
ctlMyCtls.Locked = True
subform_unlock.Caption = "UNLOCK"
Me.Refresh
End If
Next ctlMyCtls
End If

End Sub

**Note** Make sure allow edits = yes in the properties for the form

This should work for you, if you have any problems with the code get back to me

HTH