ListBox - How to Populate

N

Norman Pritchard

i am trying to make a simple UI using listboxes but this can't seem to
get anywhere. all help is APPRECIATED!!!!

- i have a simple (working) program that queries a db and prints out a
neat word doc based on it. i am currently using inputBox to get the
user input:
e.g.
============================================
Dim ProductName As String
ProductName = InputBox("Enter product name")
============================================

- now, i want to replace the input box with a listbox so that user can
select rather than having to type. so i have a form with a listbox
(lb1) and a OK button that i SHOW from the main macro:
================
frmProd.Show
================

- this form shows u fine but the listbox is always empty!!!
i have tried:
================
frmProd.lb1.AddItem "prod1"
frmProd.lb1.AddItem "prod2"
..
..
..

================

but whatever i do (also tried with array) - the listbox always shows
up empty!!!

what am i missing??

thanks much.

very very aggravating
 
C

Charles Maxson

Norman,

Your syntax is correct but are you adding the items before you show the box
right? Here's a flavor that works for me:

Sub ShowProducts()

frmProd.lb1.Clear

frmProd.lb1.AddItem "prod1"
frmProd.lb1.AddItem "prod2"

frmProd.Show

End Sub
 
P

Perry

Either add the listitems before raising the .Show command.

Or better:
Populate the listbox in the Initialize event of frmProd.

Krgrds,
Perry
 
J

Jonathan West

Hi Norman,

An alternative approach to the one Charles offered is to populate the
listbox in one go with an array containing the items you want, like this

frmProd.lb1.List = Array("prod1", "prod2", "prod3")
 
N

Norman Pritchard

thanks fellas!!!

now for the fun part of dynamically populating the list from a db.

happy new year
 

Ask a Question

Want to reply to this thread or ask your own question?

You'll need to choose a username for the site, which only take a couple of moments. After that, you can post your question and our members will help you out.

Ask a Question

Top