Results 1 to 4 of 4
  1. #1
    Simonhtc4 is offline Advanced Beginner
    Windows 10 Access 2016
    Join Date
    Mar 2017
    Posts
    30

    Ms-Access 2016 button that creates a multiple of buttons on a form

    I have my Main form that I have created a button on, when I click this button I want it to open another form and create a multiple button with names on that I pulls from a table. I have started some VBA for the button already but I'm stuck on getting it to create the buttons.Any help would greatly appreciated, I hope someone in the community can guide me in the right direction as I'm new to this area. Please see details below.Main form name HomePage_frm: VBA for the button on this form is below.Private Sub Form_Load()


    Dim SQL As String
    SQL = "Select * " & _ "FROM Users_tbl " & _ "WHERE Authority = 'Supervisor'"

    Dim rs As DAO.Recordset Set rs = CurrentDb.OpenRecordset(SQL)

    Dim strText As String

    Do While Not rs.EOF
    strText = rs.Fields("Employee_Name")'Make Buttons herers.MoveNextLoopEnd SubI have looked all over on found a few ideas but nothing seams to work.

  2. #2
    Bulzie is offline VIP
    Windows 7 64bit Access 2007
    Join Date
    Nov 2015
    Posts
    1,474
    Instead of buttons on 2nd form, how about a list box that displays all the supervisor names and when they click on a supervisor in that list box, you display that person's info or whatever?

  3. #3
    Simonhtc4 is offline Advanced Beginner
    Windows 10 Access 2016
    Join Date
    Mar 2017
    Posts
    30
    Thanks for the input, i figured away around it.
    I created the buttons on the second form and made them invisable and wrote the following code for the first from:



    Private Sub Command3_Click()
    DoCmd.OpenForm "HomePage_frm"
    DoCmd.Close acForm, "FileCheckers_frm"
    End Sub


    Private Sub Form_Current()


    End Sub


    Private Sub Form_Load()
    Dim SQL As String
    SQL = "Select * " & _
    "FROM Users_tbl " & _
    "WHERE Authority = 'Supervisor'"


    Dim rs As DAO.Recordset
    Set rs = CurrentDb.OpenRecordset(SQL)


    Dim strText As String


    Dim myNum As Integer
    myNum = 4


    Do While Not rs.EOF


    strText = rs.Fields("Employee_Name")


    Dim buttonName As String
    Dim actualButton As Control


    buttonName = "Command" & myNum


    UpdateButton buttonName, strText

    myNum = myNum + 1


    rs.MoveNext


    Loop


    End Sub


    Public Function MyOpenForm(FormName As String)
    DoCmd.OpenForm FormName
    End Function


    Private Sub UpdateButton(buttonName As String, strText As String)


    Dim cCont As Control


    For Each cCont In Me.Controls


    If TypeName(cCont) = "CommandButton" Then


    If cCont.Name = buttonName Then


    cCont.Visible = True
    cCont.Enabled = True
    cCont.Caption = strText
    cCont.ControlTipText = strText
    cCont.OnClick = "=MyOpenForm(""FileCheckSelection_frm"")"


    End If


    End If


    Next cCont


    End Sub

    I couldnt do what i wanted originally as i couldn't put the form in Design view with VBA

  4. #4
    Bulzie is offline VIP
    Windows 7 64bit Access 2007
    Join Date
    Nov 2015
    Posts
    1,474
    Good job. Seems a bit complicated to use buttons like that but at the same time, trying things out of the norm is a great way to learn coding and such.

Please reply to this thread with any new information or opinions.

Similar Threads

  1. Replies: 2
    Last Post: 03-07-2017, 04:00 PM
  2. Replies: 2
    Last Post: 11-13-2016, 08:15 AM
  3. Replies: 10
    Last Post: 09-20-2016, 03:25 PM
  4. Replies: 9
    Last Post: 07-21-2016, 08:43 AM
  5. Access 2016 Help Button?
    By Charles Hobbs in forum Misc
    Replies: 2
    Last Post: 12-16-2015, 09:39 PM

Tags for this Thread

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts
  •  
Other Forums: Microsoft Office Forums