-
Sep 3rd, 2014, 08:23 AM
#1
MS Access VBA to Outlook - This SHOULD work?
Its very strange...
I had 2 subfolders of Skipped created (Unknown and Duplicates) and was trying to set a variable to the "Unknown" folder.
it keeps erroring saying an object could not be found. SO i did the following code to test
Code:
Set OTL = New Outlook.Application
Set ONS = OTL.GetNamespace("MAPI")
Set LCDf = ONS.Folders("LCDisputeDB")
Set INBX = ONS.Folders("LCDisputeDB").Folders("Inbox")
Set SKIPD = ONS.Folders("LCDisputeDB").Folders("Skipped")
Set UNK = LCDf.Folders("Skipped").Folders.Add("Unknown")
Debug.Print SKIPD = UNK.Parent.Name 'True
Debug.Print SKIPD.FolderPath '\\LCDisputeDB\Skipped
Debug.Print UNK.FolderPath '\\LCDisputeDB\Skipped\Unknown
Set UNK2 = SKIPD.Folders("Unknown")
Set UNK works as you can see the debug results...
But when I set a variable to the Unknown it says its not there?
I can also do
Debug.Print SKIPD.folders.Count and get 0 ???
also tried
Set UNK2 = ONS.Folders("LCDisputeDB").Folders("Skipped").Folders("Unknown")
it cant see it!?? but yet UNK is created...
JPnyc rocks!! (Just ask him!)
If u have your answer please go to the thread tools and click "Mark Thread Resolved"
-
Sep 3rd, 2014, 04:22 PM
#2
Re: MS Access VBA to Outlook - This SHOULD work?
i made a similar test, works correctly for me
where test existed under inbox
Code:
Set inb = GetNamespace("mapi").GetDefaultFolder(olFolderInbox)
Set nw = inb.Folders("test").Folders.Add("mytest")
Set tst = nw
Set test2 = inb.Folders("test").Folders("mytest")
all object variables were correctly assigned
i do my best to test code works before i post it, but sometimes am unable to do so for some reason, and usually say so if this is the case.
Note code snippets posted are just that and do not include error handling that is required in real world applications, but avoid On Error Resume Next
dim all variables as required as often i have done so elsewhere in my code but only posted the relevant part
come back and mark your original post as resolved if your problem is fixed
pete
-
Sep 9th, 2014, 11:28 AM
#3
Re: MS Access VBA to Outlook - This SHOULD work?
It is probably just your hierarchy of folder structures is off. Everything is under the Inbox so you would need to drill down through it to get to a subfolder.
These are not Public Exchange folders right?
The double slashes are a different pst file? If so you have to connect to them just like you change connections in sql to different databases
VB/Office Guru™ (AKA: Gangsta Yoda™ ®)
I dont answer coding questions via PM. Please post a thread in the appropriate forum.
Microsoft MVP 2006-2011
Office Development FAQ (C#, VB.NET, VB 6, VBA)
Senior Jedi Software Engineer MCP (VB 6 & .NET), BSEE, CET
If a post has helped you then Please Rate it!
• Reps & Rating Posts • VS.NET on Vista • Multiple .NET Framework Versions • Office Primary Interop Assemblies • VB/Office Guru™ Word SpellChecker™.NET • VB/Office Guru™ Word SpellChecker™ VB6 • VB.NET Attributes Ex. • Outlook Global Address List • API Viewer utility • .NET API Viewer Utility •
System: Intel i7 6850K, Geforce GTX1060, Samsung M.2 1 TB & SATA 500 GB, 32 GBs DDR4 3300 Quad Channel RAM, 2 Viewsonic 24" LCDs, Windows 10, Office 2016, VS 2019, VB6 SP6
Posting Permissions
- You may not post new threads
- You may not post replies
- You may not post attachments
- You may not edit your posts
-
Forum Rules
|
Click Here to Expand Forum to Full Width
|