Results 1 to 4 of 4
  1. #1
    PATRICK is offline Advanced Beginner
    Windows XP Access 2003
    Join Date
    Apr 2011
    Posts
    32

    Question Form listbox button commmand

    I have a listbox in my form that has 4 coluns showing name,code,price of produtcs. then I have 45 command button in the form "cmditem1 .. to cmditem45". What Im trying to do is: i need to read the listbox and then rename the caption of the buttons command to the product name like:



    cmditem1.caption = listaproduto.Column(1, 0)

    so with that I have rename the caption of one button to the fist name of product in the list box. great! but now,how can I do a loop or whatever to rename the caption the rest of the buttons with the rest of the products names because I dont want to repeat that for each one.
    Last edited by PATRICK; 04-16-2011 at 10:18 PM.

  2. #2
    pbaldy's Avatar
    pbaldy is offline Who is John Galt?
    Windows XP Access 2007
    Join Date
    Feb 2010
    Location
    Nevada, USA
    Posts
    22,521
    Not sure about the practicality of 45 buttons, but you could have a For/Next loop and use the loop variable in your code:

    For x = 1 To 45
    Me("cmditem" & x).caption = listaproduto.Column(1, x-1)
    Paul (wino moderator)
    MS Access MVP 2007-2019
    www.BaldyWeb.com

  3. #3
    PATRICK is offline Advanced Beginner
    Windows XP Access 2003
    Join Date
    Apr 2011
    Posts
    32
    Thanks Paul, I adapted your code its working very good. the thing is like I have only 45 buttons and then some categories had less itens then 45 and was rename the buttons but after I had a error message because didn't had data for the rest of the buttons, so here what I did for someone that wants to use it:

    //
    For X = 0 To listaproduto.ListCount - 1
    For Y = listaproduto.ListCount To 44
    Me("cmditem" & X).Caption = listaproduto.Column(1, X)
    Me("cmditem" & Y).Caption = " " or .visible = false //if you want to hide the rest
    //


    where "x" represents the total of products in the listbox will rename the caption. If the list box has only 15, the code will rename only 15 buttons. and "Y" is the rest of the buttons that you can hide the caption or the button.

  4. #4
    pbaldy's Avatar
    pbaldy is offline Who is John Galt?
    Windows XP Access 2007
    Join Date
    Feb 2010
    Location
    Nevada, USA
    Posts
    22,521
    Happy to help.
    Paul (wino moderator)
    MS Access MVP 2007-2019
    www.BaldyWeb.com

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

Similar Threads

  1. Replies: 29
    Last Post: 02-13-2011, 01:21 AM
  2. Form ListBox Know-how
    By InThrees in forum Forms
    Replies: 5
    Last Post: 12-03-2010, 01:02 PM
  3. Update form when data collected from Listbox
    By Evetsllub in forum Forms
    Replies: 1
    Last Post: 06-10-2010, 05:33 PM
  4. Replies: 1
    Last Post: 03-24-2010, 08:42 AM
  5. Query criteria retrieved from a Form's listbox
    By blacksaibot in forum Programming
    Replies: 1
    Last Post: 01-29-2010, 10:38 AM

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