Dynamically populate a form from a table record

atiqahmed

New member
Local time
Today, 23:03
Joined
Mar 17, 2021
Messages
22
Hi everyone, I want to insert captions of button from a table record. please help me to complete this task. my accdb file is attached for your referance.
 

Attachments

Code:
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
 
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?
 
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 datasheet?
 
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
1683397512757.png

i got the results like this, would you please help me.
 
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.
1683399651552.png
 
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
Maybe take a look at Calendar examples where multiple subforms are used to represent each date in a month with all its events.
 
Something you can adapt here - post #10
 
This can be done nicely with a little web browser programming. It was fun. I might add a few extra bits that it requires if you're interested.

Untitled.jpg
 

Attachments

Thank you so much all of you, your provided samples are awesome and I think my requirements are going to fulfill, I will share my template with you once completed.
 

Users who are viewing this thread

Back
Top Bottom