This is the example I took it from https://www.youtube.com/watch?v=80OgXS9nvvM
This is the example I took it from https://www.youtube.com/watch?v=80OgXS9nvvM
I don't feel like watching a video right now, but you definitely can't specify a value for Controls higher than the count minus one.
So what is the fix in this code? remove the -1?
'this Sub Implements sort-buttons in an OptionGroup
Sub FillButtons(oFrm As Form, oFra As OptionGroup)
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
My first thought was to get rid of the +1.
It did not work for me. So to keep it simple. lets say I add a toggle button. When I depress the button the column sorts Ascending. When I release the toggle it sorts Descending. How would I code this?
Private Sub Frame61_AfterUpdate()
?
End Sub
Something like this?
Private Sub Toggle102_AfterUpdate()
If Toggle102.Value = True Then
DoCmd.SetOrderBy OrderNum, DESC
Else
DoCmd.SetOrderBy OrderNum, Asc
End If
End Sub
Never used that, more like:
Me.OrderBy = "OrderNum DESC"
Me.OrderByOn = True
Yup - me too.
I answered this in the parallel thread here: https://www.accessforums.net/showthr...393#post404393
Had to check the syntax was still the same using DoCmd.SetOrderBy
Code:Private Sub Toggle102_AfterUpdate() If Toggle102.Value = True Then DoCmd.SetOrderBy "OrderNum DESC" Else DoCmd.SetOrderBy "OrderNum ASC" End If End Sub