Const maxButtons = 4
Private Sub Form_Load()
Dim rs As DAO.Recordset
Dim i As Integer
Dim ctrl As Access.CommandButton
Set rs = CurrentDb.OpenRecordset("PickButtonName")
Do While Not rs.EOF And i < maxButtons
Set ctrl = Me.Controls("Command" & i)
With ctrl
.OnClick = "= CommonEvent()"
.Caption = rs!MyName
End With
i = i + 1
rs.MoveNext
Loop
End Sub
Public Function CommonEvent()
MsgBox Me.ActiveControl.Caption
End Function
its worked but froms shows only 4 records meanwhile it has many records, does it possible to show buttons according to records?Const maxButtons = 4 Private Sub Form_Load() Dim rs As DAO.Recordset Dim i As Integer Dim ctrl As Access.CommandButton Set rs = CurrentDb.OpenRecordset("PickButtonName") Do While Not rs.EOF And i < maxButtons Set ctrl = Me.Controls("Command" & i) With ctrl .OnClick = "= CommonEvent()" .Caption = rs!MyName End With i = i + 1 rs.MoveNext Loop End Sub Public Function CommonEvent() MsgBox Me.ActiveControl.Caption End Function
So you are not understanding the code supplied?
How many buttons do you have on your form?, how many records are you talking about?
Have you looked at a continuous form, or datas
Maybe take a look at Calendar examples where multiple subforms are used to represent each date in a month with all its events.Actually, i want to design a form where i can see attendance of students, i have done with single column using continous form but i want to design another form with 4 or 5 columns like given below snape. if a class have 100 students so, it should be displayed like below and when i select an other class so, it should be changed according to class.
View attachment 107855