Tek-Tips is the largest IT community on the Internet today!

Members share and learn making Tek-Tips Forums the best source of peer-reviewed technical information on the Internet!

  • Congratulations biv343 on being selected by the Tek-Tips community for having the most helpful posts in the forums last week. Way to Go!

Set subforms' AllowAdditions from Main Form_Current

Status
Not open for further replies.

HomeGrowth

Technical User
Aug 19, 2004
76
US
I have this code on the Form_Current( ) of the main form.

Dim ctl As Control

If Me.ynoLocked = -1 Then 'Check for the locked is checked.
'go thgouh the subform, and lock this up.
For Each ctl In Me.Controls
If ctl.ControlType = acSubform Then
If ctl.Form.Tag = "L" Then 'skip this subform that doesn't have L tag
ctl.Form.AllowEdits = False
ctl.Form.AllowAdditions = False
End If
End If
Next
Else
'go thgouh the subform, and UNLOCK this up.
For Each ctl In Me.Controls
If ctl.ControlType = acSubform Then
If ctl.Form.Tag = "L" Then 'skip this subform that doesn't have L tag
ctl.Form.AllowEdits = True
ctl.Form.AllowAdditions = True
End If
End If
Next
End If

I got Run-Time error ‘2455’: You entered an expression that has an invalid reference to the property Form/Report.

I created a button on the main form using the above codes, this button works fine to AllowEdits and AllowAdditions for all subforms (that has the tag property = ‘L”).

So, my question: How do I get the subforms prevent edit and addition if the Locked field is true on the main form from a record to another. Thanks!
 
What line is causing the problem? The above works for me in a mock-up.
 
How are ya HomeGrowth . . .

I get the same results as [blue]Remou[/blue]!

Note: since [blue]ynoLocked[/blue] simply determines true or false, set a variable and run thru a single loop instead:
Code:
[blue]   Dim ctl As Control, flg As Boolean
   
   If Me.ynoLocked <> -1 Then flg = True
   
   For Each ctl In Me.Controls
      If ctl.ControlType = acSubform Then
         If ctl.Form.Tag = "L" Then
             ctl.Form.AllowEdits = flg
             ctl.Form.AllowAdditions = flg
         End If
      End If
   Next[/blue]

Calvin.gif
See Ya! . . . . . .

Be sure to see thread181-473997
Also faq181-2886
 
Thanks TheAceMan1, I like the codes.

Dim ctl As Control, flg As Boolean

If Me.ynoLocked <> -1 Then flg = True

For Each ctl In Me.Controls
If ctl.ControlType = acSubform Then
If ctl.Form.Tag = "L" Then
ctl.Form.AllowEdits = flg
ctl.Form.AllowAdditions = flg
End If
End If
Next

However, this line is causing the problem
If ctl.Form.Tag = "L" Then
in debug, the error stated:
ctl.Form.Tag =<You entered an expression that has an invilit reference to t... (I can't see the rest).

Again, it works on the button, but it DOESN'T on the Form_Current event on the main form.

Any more suggestion? Thanks!
 
Your problem is that you aren't referencing a subform properly. You are checking to see if the control type is acSubform but you aren't checking the subform itself.

So, you would need
Code:
Dim ctl As Control, flg As Boolean
   
   If Me.ynoLocked <> -1 Then flg = True
   
   For Each ctl In Me.SubformContainerNameHere.Form.Controls
         If ctl.Form.Tag = "L" Then
             ctl.Form.AllowEdits = flg
             ctl.Form.AllowAdditions = flg
         End If
   Next


Bob Larson
A2K,A2K3,A2K7,SQL Server 2000/2005,Crystal Reports 10/XI,VB6, WinXP, and Vista
Free Quick Tutorials and Samples:
 
HomeGrowth . . .

Try:
Code:
[blue]   If ctl.Tag = "L" Then

or

   If Me(ctl.Name).Form.Tag = "L" Then[/blue]

Calvin.gif
See Ya! . . . . . .

Be sure to see thread181-473997
Also faq181-2886
 
Hi Bob,

What do you mean SubformContainerNameHere in For Each ctl In Me.SubformContainerNameHere.Form.Controls . I tried to replace the Subform Name, the same Run-Time error ‘2455’: You entered an expression that has an invalid reference to the property Form/Report.

Hi TheAceMan

I tried If ctl.Tag = "L" Then, no thing happens. Not even has an error.

I tried If Me(ctl.Name).Form.Tag = "L" Then. I got the same Run-Time error ‘2455’: You entered an expression that has an invalid reference to the property Form/Report.

Something that I don’t understand is the Botton that I created works perfect (because the main is seeing all subform). I need to code on the Form_Cuurent to lock the subforms, somehow, the main form doesn’t seem to see the subforms’ property. Why!? Is there because I have some other codes in Form_Current event? Any other ideas? Thanks for your suggestions.
 
HomeGrowth
Can you attach your database or a partial copy to your next post, please?
 
SubformContainerNameHere means just that - use the container control name (name of the container that houses the subform on the main form) NOT the subform name (although the subform container name and the subform name CAN be the same thing, it isn't always, so you need to use the CONTAINER name, not the subform name).

See here which includes a screenshot explaining that:



Bob Larson
A2K,A2K3,A2K7,SQL Server 2000/2005,Crystal Reports 10/XI,VB6, WinXP, and Vista
Free Quick Tutorials and Samples:
 
I found the problem, it is the

doCmd.GoToRecord, , acNerRecord

on On_Open event causing the problem, I moved this code to On_Load event. Everything is working perfectly.

Thank you all.
 
Status
Not open for further replies.

Part and Inventory Search

Sponsor

Back
Top