How to

I have a VBA running in outlook 2010 where it asks for a mailbox (to search from).

This code was originally set up so that the user can select ANY mailbox to start searching in, however, I only need it to always start in the normal "Inbox".

I have tried everything, but I can't seem to get it.  It presents me with a dialog box (which I will always just pick the Inbox) and the code proceeds without any problems.

  'Set the start folder under which it will search
  '*********I don't know how to set it automatically to INBOX
  Set F = Application.Session.PickFolder

If Not F Is Nothing Then
    Set Folders = F.Folders
    DaFolder = Mid(F.FolderPath, 3)
.
.
.
.

Open in new window


What can I change the line
Set F = Application.Session.PickFolder
with so that it has automatically assigned the "Inbox" to F?
MoeMoe7Asked:
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.

MacroShadowCommented:
Try this:
Dim f As MAPIFolder
Dim olns As Outlook.NameSpace
Set olns = Outlook.GetNamespace("MAPI")
Set f = olns.Folders("Mailbox - Name, Name")
Set f = f.Folders("Inbox")

Open in new window

0
Dany BalianCTOCommented:
modify your code to the following: (for only one time run, select the inbox, and note the values returned)

'Set the start folder under which it will search
'*********I don't know how to set it automatically to INBOX
Set F = Application.Session.PickFolder
Dim myEntryID As String, myStoreID As String
myEntryID = F.EntryID 
myStoreID = F.StoreID
msgbox "myentryid="  & myentryid & vbcrlf & "mystoreid=" & mystoreid

Open in new window


then modify your code to the following:
Set F = Application.Session.GetFolderFromID(myEntryID, myStoreID) 'use the values that you got from step 1

Open in new window


hope this helps..
0
MoeMoe7Author Commented:
MacroShadow,

This is what I did:  (it did not work)

Private F As Outlook.MAPIFolder
Private Folders As Outlook.Folders
Private DaFolder As String
Private DaFolder2 As String
Private olns As Outlook.NameSpace
.
.
.
  'Set the start folder underwhich it will search
  '*********I don't know how to set it automatically to INBOX
    Set olns = Outlook.GetNamespace("MAPI")
    Set F = olns.Folders("Mailbox - Name, Name")
    Set F = F.Folders("Inbox")
    'Set F = Application.Session.PickFolder

Open in new window


It fails at
Set F = olns.Folders("Mailbox - Name, Name")

I dimensioned them like that because that is how I had the code and I am afraid to break other things down the line if I changed it.

How is this different from yours? Obviously the lines are different:
yours:  Dim f As MAPIFolder
mine:   Private Folders As Outlook.Folders

Are they not equivalent?
0
Ultimate Tool Kit for Technology Solution Provider

Broken down into practical pointers and step-by-step instructions, the IT Service Excellence Tool Kit delivers expert advice for technology solution providers. Get your free copy now.

MoeMoe7Author Commented:
Dany,

I understand that your code is basically seeing what the selection values are and I can see how that would work. But what are these values exactly?  And, if I port the code over to another computer, will these values have changed?

That is, I like it, but I am afraid it will be too custom.  What could go wrong?
0
Dany BalianCTOCommented:
oh, i thought that you were doing something just for one time, on one computer.. of course my solution is too custom.

then you have to get the folder using a folder path.

Function GetFolder(ByVal FolderPath As String) As Outlook.Folder
    Dim TestFolder As Outlook.Folder
    Dim FoldersArray As Variant
    Dim i As Integer
        
    On Error GoTo GetFolder_Error
    If Left(FolderPath, 2) = "\\" Then
        FolderPath = Right(FolderPath, Len(FolderPath) - 2)
    End If
    'Convert folderpath to array
    FoldersArray = Split(FolderPath, "\")
    Set TestFolder = Application.Session.Folders.item(FoldersArray(0))
    If Not TestFolder Is Nothing Then
        For i = 1 To UBound(FoldersArray, 1)
            Dim SubFolders As Outlook.Folders
            Set SubFolders = TestFolder.Folders
            Set TestFolder = SubFolders.item(FoldersArray(i))
            If TestFolder Is Nothing Then
                Set GetFolder = Nothing
            End If
        Next
    End If
    'Return the TestFolder
    Set GetFolder = TestFolder
    Exit Function
        
GetFolder_Error:
    Set GetFolder = Nothing
    Exit Function
End Function

Sub TestGetFolder()
    Dim folder As Outlook.Folder
    Set folder = GetFolder ("\\Mailbox - Dan Wilson\Inbox\Customers")
    If Not(folder Is Nothing) Then
	folder.Display
    End If
End Sub

Open in new window


Source: How to: Obtain a Folder Object from a Folder Path
0
MoeMoe7Author Commented:
Holy!

That seems like a lot of code for something quite basic, no?

Isn't there a simply method that simply says get the default mailbox inbox?
0
Dany BalianCTOCommented:
well.. i don't think there's a simple method that gets that.. i didn't write that code, just found it from the msdn.. anyways, you can check the following resource for available concepts from the msdn regarding Items, Folders, and Stores
0
MacroShadowCommented:
Try:
Dim f As MAPIFolder
Dim olns As Outlook.NameSpace
Set olns = Outlook.GetNamespace("MAPI")
Set f = olns.Folders("Mailbox - Name, Name")
Set f = f.Folders("Inbox")

Open in new window

Where "Name" is the name of the email account. e.g. Set f = olns.Folders("Mailbox - MoeMoe7, MoeMoe7")
0

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
MoeMoe7Author Commented:
I'll try that tomorrow.
0
Martin LissOlder than dirtCommented:
This question has been classified as abandoned and is closed as part of the Cleanup Program. See the recommendation for more details.
0
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
Microsoft Office

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.