Repost still looking for help on subforms (1 Viewer)

C

Chucklinn

Guest
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

Registered User.
Local time
Today, 00:34
Joined
Aug 7, 2000
Messages
2,639
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

Registered User.
Local time
Today, 00:34
Joined
May 9, 2001
Messages
92
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
 

Users who are viewing this thread

Top Bottom