how to make combo box list = contents of windows folder?

K

Kim M.

Hi and thanks in advance. I'm using Access 2007.

I would like to have a combo box display as its options a list of files
contained in a certain folder, and then when user selects a file using the
combo box, open it. (Incidentally, these will all be .docx files.)

I have the opening part already figured out. For now, I have just been
manually adding the name of the file to the combo box list whenever I add a
new document to the folder. But, as the contents of the target folder are
constantly changing, this solution can obviously get very tedious. So I'd
like to have Access "peek" into the folder by itself and use its contents as
the choices for the combo box.

I know there must be a way to do this, but haven't been able to figure it
out. I've only been programming for about a year, so don't be afraid to
"dumb it down" for me!

Thanks for your help!
 
K

Kim M.

Hi Jack. I've got this up and running pretty well (thanks -- would never
have been able to do it on my own!!) But have one glitch. When I delete a
file from the target folder and then open the form with the list box again,
what is displayed is the complete list of files WITH the deleted file, PLUS
another complete list just below it WITHOUT the deleted file. This happens
even if I close and open the form (in fact, it happens even if I close and
open the whole database!)

I'm thinking there is a variable somewhere that is not getting cleared, such
that it "remembers" the prior list and then tacks on the new one (??), but I
can't figure out where. Any thoughts?

Thanks so much,
Kim M.
 
K

Kim M.

Hi Jack. I've got this up and running pretty well (thanks -- would never
have been able to do it on my own!!) But have one glitch. When I delete a
file from the target folder and then open the form with the list box again,
what is displayed is the complete list of files WITH the deleted file, PLUS
another complete list just below it WITHOUT the deleted file. This happens
even if I close and open the form (in fact, it happens even if I close and
open the whole database!)

I'm thinking there is a variable somewhere that is not getting cleared, such
that it "remembers" the prior list and then tacks on the new one (??), but I
can't figure out where. Any thoughts?

Thanks so much,
Kim M.
 
J

Jack Leach

It sounds like the list box is not being emptied of the previously loaded
files before you are adding them. I'm guessing you're going to want a
routine to clear the contents of the list.

If the row source type is set to value list (per Allen's suggest, but you
may have made some modifications?), then you should be able to clear the
values with one line of code before calling the procedure to fill them with
filenames again:

Me.ListBoxName.RowSource = ""

You should be able to run this right before you call Allen's function, or
maybe integrate it with Allen's existing function (an additional optional
argument to remove old values in a list box before adding would probably be
my choice... then it's all in one function and you can still use the function
elsewhere without having to clear the values first)


hth
--
Jack Leach
www.tristatemachine.com

"I haven't failed, I've found ten thousand ways that don't work."
-Thomas Edison (1847-1931)
 
J

Jack Leach

It sounds like the list box is not being emptied of the previously loaded
files before you are adding them. I'm guessing you're going to want a
routine to clear the contents of the list.

If the row source type is set to value list (per Allen's suggest, but you
may have made some modifications?), then you should be able to clear the
values with one line of code before calling the procedure to fill them with
filenames again:

Me.ListBoxName.RowSource = ""

You should be able to run this right before you call Allen's function, or
maybe integrate it with Allen's existing function (an additional optional
argument to remove old values in a list box before adding would probably be
my choice... then it's all in one function and you can still use the function
elsewhere without having to clear the values first)


hth
--
Jack Leach
www.tristatemachine.com

"I haven't failed, I've found ten thousand ways that don't work."
-Thomas Edison (1847-1931)
 
K

Kim M.

Worked like a charm! Thanks!

Jack Leach said:
It sounds like the list box is not being emptied of the previously loaded
files before you are adding them. I'm guessing you're going to want a
routine to clear the contents of the list.

If the row source type is set to value list (per Allen's suggest, but you
may have made some modifications?), then you should be able to clear the
values with one line of code before calling the procedure to fill them with
filenames again:

Me.ListBoxName.RowSource = ""

You should be able to run this right before you call Allen's function, or
maybe integrate it with Allen's existing function (an additional optional
argument to remove old values in a list box before adding would probably be
my choice... then it's all in one function and you can still use the function
elsewhere without having to clear the values first)


hth
--
Jack Leach
www.tristatemachine.com

"I haven't failed, I've found ten thousand ways that don't work."
-Thomas Edison (1847-1931)
 
K

Kim M.

Worked like a charm! Thanks!

Jack Leach said:
It sounds like the list box is not being emptied of the previously loaded
files before you are adding them. I'm guessing you're going to want a
routine to clear the contents of the list.

If the row source type is set to value list (per Allen's suggest, but you
may have made some modifications?), then you should be able to clear the
values with one line of code before calling the procedure to fill them with
filenames again:

Me.ListBoxName.RowSource = ""

You should be able to run this right before you call Allen's function, or
maybe integrate it with Allen's existing function (an additional optional
argument to remove old values in a list box before adding would probably be
my choice... then it's all in one function and you can still use the function
elsewhere without having to clear the values first)


hth
--
Jack Leach
www.tristatemachine.com

"I haven't failed, I've found ten thousand ways that don't work."
-Thomas Edison (1847-1931)
 

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