Dynamically populate a form from a table record (1 Viewer)

atiqahmed

New member
Local time
Today, 23:32
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

  • Database3.accdb
    704 KB · Views: 73

MajP

You've got your good things, and you've got mine.
Local time
Today, 14:32
Joined
May 21, 2018
Messages
8,529
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
 

Pat Hartman

Super Moderator
Staff member
Local time
Today, 14:32
Joined
Feb 19, 2002
Messages
43,277
Here's a couple of switchboard examples if that is what you are trying to replicate. One of them is big buttons. The form has 12 (or maybe 16) buttons. You can have as many as you want. you just have to change ONE line of code to put the max button number in and you have to add the buttons, named correctly, to the form.

The sample also includes a maintenance form since once you go past 8 items, the switchboard wizard won't work for you any more.

 

atiqahmed

New member
Local time
Today, 23:32
Joined
Mar 17, 2021
Messages
22
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?
 

Gasman

Enthusiastic Amateur
Local time
Today, 19:32
Joined
Sep 21, 2011
Messages
14,310
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?
 

atiqahmed

New member
Local time
Today, 23:32
Joined
Mar 17, 2021
Messages
22
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.
 

Pat Hartman

Super Moderator
Staff member
Local time
Today, 14:32
Joined
Feb 19, 2002
Messages
43,277
You probably need to tell us why you need this. The technique posted in code and in my sample is very useful for creating menus where you have some control over the number of items to be displayed on a form.

This is not a suitable solution for a normal recordset such as a customer list for example. Using a combo, listbox, or subform would be a better solution if you cannot control the number of items. Technically, you could write code that counts the number of items and then builds a form from scratch to handle that number of items. But, regardless, the number of controls on a form is limited to ~ 900 and it is not possible to exceed that.
 

atiqahmed

New member
Local time
Today, 23:32
Joined
Mar 17, 2021
Messages
22
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
 

theDBguy

I’m here to help
Staff member
Local time
Today, 11:32
Joined
Oct 29, 2018
Messages
21,474
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.
 

CJ_London

Super Moderator
Staff member
Local time
Today, 19:32
Joined
Feb 19, 2013
Messages
16,616
Something you can adapt here - post #10
 

Pat Hartman

Super Moderator
Staff member
Local time
Today, 14:32
Joined
Feb 19, 2002
Messages
43,277
Based on the picture, the sample I posted will work fine. You just need to limit the number of boxes per form. The list on the left can be a listbox or a subform and it can be used to filter another subform on the right side of the form. Take a little initiative and replace the [Switchboard Items] table values with some data you want to see. Don't do any coding. Don't worry about the pictures. Just let the form work as it currently does until you understand the method. Once you understand how it works, you can create the list form and put both onto an unbound main form and let the list drive the boxes.
 

561414

Active member
Local time
Today, 13:32
Joined
May 28, 2021
Messages
280
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

  • flex.accdb
    476 KB · Views: 61

atiqahmed

New member
Local time
Today, 23:32
Joined
Mar 17, 2021
Messages
22
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

Top Bottom