Change folder name dynamically


I am working with MS Access, I have my Outlook folder names in my ComboBox cboFolders, and MAPI folder as cboMapi
I know these lines work:

Set OlFolder = OlMapi.Folders("Personal Folders").Folders("Inbox")
Set OlFolderTo = OlMapi.Folders("Personal Folders").Folders("Inbox")

but instead, I want to select the folder names from my ComboBoxes, like this:

Set OlFolder = OlMapi.Folders("Personal Folders").Folders("Inbox")
Set OlFolderTo = OlMapi.Folders([cboMapi]).Folders([cboFolders])

Thanks in advance

LVL 27
Who is Participating?
I wear a lot of hats...

"The solutions and answers provided on Experts Exchange have been extremely helpful to me over the last few years. I wear a lot of hats - Developer, Database Administrator, Help Desk, etc., so I know a lot of things but not a lot about one thing. Experts Exchange gives me answers from people who do know a lot about one thing, in a easy to use platform." -Todd S.

David LeeCommented:
Greetings, jjafferr.

> I am working with MS Access
I assume that means that this code is in Access.  If so, then this is really an Access question, not an Outlook one.  You can certainly use dynamic values instead of hard coded ones, the question is how Access substitutes the value into the code.  I'm not deep enough into Access to be able to answer that.  You can try a simple test though to show that dynamic values are possible.  Try this:

    Set OlFolder = OlMapi.Folders("Personal Folders").Folders("Inbox")
    strContainer = [cboMapi]
    strFolder = [cboFolders]
    Set OlFolderTo = OlMapi.Folders(strContainer).Folders(strFolder)

Replace  [cboMapi] and [cboFolders] with whatever the proper syntax is in Access to retrieve a value from control.


Experts Exchange Solution brought to you by

Your issues matter to us.

Facing a tech roadblock? Get the help and guidance you need from experienced professionals who care. Ask your question anytime, anywhere, with no hassle.

Start your 7-day free trial
jjafferrAuthor Commented:

I have tried all the "un-obvious", but missed the obvious,
Right on the money, thanks a bunch.

just have to declare
Dim strContainer,strFolder as string

David LeeCommented:
You're welcome.  Glad it worked out.
It's more than this solution.Get answers and train to solve all your tech problems - anytime, anywhere.Try it for free Edge Out The Competitionfor your dream job with proven skills and certifications.Get started today Stand Outas the employee with proven skills.Start learning today for free Move Your Career Forwardwith certification training in the latest technologies.Start your trial today

From novice to tech pro — start learning today.

Question has a verified solution.

Are you are experiencing a similar issue? Get a personalized answer when you ask a related question.

Have a better answer? Share it in a comment.