Change folder name dynamically

Posted on 2006-04-11
Last Modified: 2010-05-18

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

Question by:jjafferr
    LVL 76

    Accepted Solution

    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.

    LVL 27

    Author Comment


    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

    LVL 76

    Expert Comment

    by:David Lee
    You're welcome.  Glad it worked out.

    Write Comment

    Please enter a first name

    Please enter a last name

    We will never share this with anyone.

    Featured Post

    Looking for New Ways to Advertise?

    Engage with tech pros in our community with native advertising, as a Vendor Expert, and more.

    Learn more about the importance of email disclaimers with our top 10 email disclaimer DOs and DON’Ts.
    Use these top 10 tips to master the art of email signature design. Create an email signature design that will easily wow recipients, promote your brand and highlight your professionalism.
    Get people started with the process of using Access VBA to control Outlook using automation, Microsoft Access can control other applications. An example is the ability to programmatically talk to Microsoft Outlook. Using automation, an Access applic…
    This Experts Exchange video Micro Tutorial shows how to tell Microsoft Office that a word is NOT spelled correctly. Microsoft Office has a built-in, main dictionary that is shared by Office apps, including Excel, Outlook, PowerPoint, and Word. When …

    761 members asked questions and received personalized solutions in the past 7 days.

    Join the community of 500,000 technology professionals and ask your questions.

    Join & Ask a Question

    Need Help in Real-Time?

    Connect with top rated Experts

    11 Experts available now in Live!

    Get 1:1 Help Now