Creating Buttons On Run-VBForums
Results 1 to 3 of 3

Thread: Creating Buttons On Run

  1. #1

    Thread Starter
    New Member
    Join Date
    Apr 2012
    Posts
    2

    Creating Buttons On Run

    Hey guys, I've been trying to figure this out for a couple days now and haven't gotten very far.

    I have a database of table #'s (for a room in a restaurant) that I need to generate buttons for. The database is tables.mdb, and the table I want to generate buttons from is tabnum.

    Code:
    Public Function disptables()
            Dim x As Integer
            x = 5
            Dim NB As New Button
            Dim dt As New DataTable
            Dim ds As New DataSet
            ds.Tables.Add(dt)
            con.Open()
            Dim da As New OleDb.OleDbDataAdapter("select TabNum from TabNum", con)
            da.Fill(dt)
            For Each DataRow In dt.Rows
                x = x + 20
                NB.Left = 5
                NB.Top = 5 + x
                NB.Name = "TBL" & DataRow(0)
                NB.Text = "TABLE " & DataRow(0)
                Me.Controls.Add(NB)
            Next
            con.Close()
            Return True
        End Function
    This code only generates a button for the last table number in the DB. What am I doing wrong?


  2. #2
    PowerPoster cicatrix's Avatar
    Join Date
    Dec 2009
    Location
    Moscow, Russia
    Posts
    3,654

    Re: Creating Buttons On Run

    Because you only created one (you create something using the new keyword)
    This must be placed within the for...next loop:
    Code:
    Dim NB As New Button

  3. #3

    Thread Starter
    New Member
    Join Date
    Apr 2012
    Posts
    2

    Re: Creating Buttons On Run

    Quote Originally Posted by cicatrix View Post
    Because you only created one (you create something using the new keyword)
    This must be placed within the for...next loop:
    Code:
    Dim NB As New Button
    Right as I was about to go to bed I noticed that... Just as you said, it fixed it.

    Doh.

    Thanks!

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts
  •  



Featured


Click Here to Expand Forum to Full Width

Survey posted by VBForums.