Fixed first error. it was DoCmd.Mazimize. Corrected to DoCmd.Maximize
New error Run-time error '2467':
The expression you entered refers to an object that is clised or doesn't exist
Highlighted this row Set oTgl = oFra.Controls(i + 1) '0 is its label
Never tried to loop a frame like that. Hit Debug when it errors and see what i is by hovering over it. Make sure it's appropriate to the number of controls in the frame. Can you attach the db here?
Hover over i and see what its value is, or in the Immediate window type:
?i
i = 1 is what it is
My goal is to create a sort filter for my tabular form
So it went successfully through the loop once? Type this in the Immediate window:
?Forms!FormName.FrameName.Controls.Count
replacing the form name and whichever frame this is failing on.
I've used frames for sorting, but never needed to dynamically control it like that.
Sorry Im new to this. Is this how you want the above added?
'this Sub Implements sort-buttons in an OptionGroup
Sub FillButtons(oFrm As Form, oFra As OptionGroup)
Print Forms!frmOrderStatus.Frame64.Controls.Count
Dim oRS As DAO.Recordset, i As Integer
Dim oTB As TextBox, oTgl As ToggleButton
Set oRS = oFrm.RecordsetClone
For i = 0 To oRS.Fields.Count - 1
Set oTB = oFrm.Detail.Controls(i)
Set oTgl = oFra.Controls(i + 1) '0 is its label
oTB.ControlSource = oRS.Fields(i).Name
oTgl.Caption = oRS.Fields(i).Name
oTgl.Left = oTB.Left
oTgl.Width = oTB.Width
oTB.Locked = True 'so no editing here
Next i
oFrm.AllowAdditions = False 'so no new records here
DoCmd.Maximize
End Sub
No, I suggested typing it into the Immediate window. I'm trying to see if the frame being worked on has the expected number of controls. I understand you can't post the actual db, but a representative sample would help.
?Forms!frmOrderStatus.Frame65.Controls.Count
2
And are there 2 toggle buttons, or 1 plus the label? I think the controls collection is zero based, so when i=1, 1+1=2, and 2 wouldn't be a valid value thus your error. Maybe adding 1 is a mistake?
I just played around, and an option group that reports 4 as the count throws your error if I do:
?reports!rptBreakDownSheet.fraSort.Controls(4).nam e
so it's definitely zero based.