• Status: Solved
  • Priority: Medium
  • Security: Public
  • Views: 310
  • Last Modified:

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

  • 2
1 Solution
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.

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.

Featured Post

Granular recovery for Microsoft Exchange

With Veeam Explorer for Microsoft Exchange you can choose the Exchange Servers and restore points you’re interested in, and Veeam Explorer will present the contents of those mailbox stores for browsing, searching and exporting.

  • 2
Tackle projects and never again get stuck behind a technical roadblock.
Join Now