Olmailitem Error
Contents |
Forums Excel Questions What "type" should olMailItem be? Results 1 to 4 of 4 What "type" should olMailItem be?This is a olmailitem variable not defined discussion on What "type" should olMailItem be? within the Excel Questions forums,
Olmailitem Vba
part of the Question Forums category; Hi all, I can make the below subroutine work if I olmailitem attachment declare olMailItem as Variant . But, as I understand ... LinkBack LinkBack URL About LinkBacks Bookmark & Share Digg this Thread!Add Thread to del.icio.usBookmark in TechnoratiTweet this thread
Outlook Vba Runtime Error 91
Thread Tools Show Printable Version Display Linear Mode Switch to Hybrid Mode Switch to Threaded Mode Apr 12th, 2012,08:50 AM #1 squidgeny Board Regular Join Date Jul 2011 Posts 128 What "type" should olMailItem be? Hi all, I can make the below subroutine work if I declare olMailItem as Variant. But, as I understand it (and my olmailitem value understanding is somewhat limited - I'm new to VBA), Variant is a sort of wildcard. Can anyone tell me what it specifically should be? I've tried Outlook.MailItem but that gives me a "User-defined type not defined" error. Code: Option Explicit Sub testEmail() Dim myOutlook As Object Dim myMailItem As Object Set myOutlook = CreateObject("Outlook.Application") Set myMailItem = myOutlook.CreateItem(olMailItem) myMailItem.Display Set myMailItem = Nothing Set myOutlook = Nothing End Sub Share Share this post on Digg Del.icio.us Technorati Twitter Reply With Quote Apr 12th, 2012,09:01 AM #2 Andrew Poulsom MrExcel MVPModerator Join Date Jul 2002 Posts 73,092 Re: What "type" should olMailItem be? You can use OutLook.MailItem if you have set a reference to Outlook (early binding). Otherwise it's Object. Share Share this post on Digg Del.icio.us Technorati Twitter Microsoft MVP - Excel Reply With Quote Apr 12th, 2012,09:04 AM #3 ZVI MrExcel MVP Join Date Apr 2008 Location Sevastopol Posts 3,071 Re: What "type" should olMailItem be? Hi, olMailItem is the Outlook's constant equal to zero. Without reference (VBE-Tools-References) to Ou
Custom Search UtterAccess Forums>Microsoft® Access>Access Modules Sending Email With Outlook - Error 91: Object Varialbe Not Set, Office 2010 Forum
Run-time Error '91' Object Variable Or With Block Variable Not Set
HomeSearchHelpUA Messages|-- UtterAccess.com NewsAccess Knowledge Center|-- Access Code Archive|-- Access Knowledgebase
Object Variable Or With Block Variable Not Set Vba
/ FAQ|-- Access TutorialsMicrosoft® Access|-- Local Access User Groups (AUGs)|-- Interface Design|-- Access Q and A|-- Access Tables + Relationships|-- Access Queries|-- Access Forms|-- Access Reports|-- Access Macros|-- Access Modules|-- Access Date + Time|-- Access Errors + Error Handling|-- Access Built-in Functions|-- http://www.mrexcel.com/forum/excel-questions/628036-what-type-should-olmailitem.html Access Searching + Data Mining|-- Access Records|-- Access Security|-- Access Automation|-- Access Database Container|-- Tool bars, Menu bars + Ribbon|-- Access Services (Web Databases)|-- Access Data Access Pages (Deprecated)|-- Access Data Projects - ADP|-- Access Runtime, Packaging & DeploymentAnd More...|-- Microsoft SQL Server|-- SQL Server Reporting Services|-- Microsoft SharePoint|-- Microsoft Internet Explorer|-- Visual Basic http://www.utteraccess.com/forum/index.php?showtopic=1960377 6 and Earlier|-- Visual Basic 2003 and Later|-- ASP and VBScript|-- Web Development|-- PHP, Perl, MySQL and Postgres|-- Other Database Engines|-- BI Tools and Applications|-- JAVA and C#|-- GraphicsMicrosoft® Office|-- Microsoft Excel|-- Microsoft Excel FAQs|-- Microsoft Word|-- Microsoft Outlook|-- Microsoft PowerPoint|-- Microsoft FrontPage/Exp. Web|-- Other Microsoft ProductsPC|-- Network Issues|-- Q & A - Hardware|-- Q & A - Software|-- Q & A - Other PC|-- Virus + Security DiscussionUtterAccess Odds and Ends|-- General Chat|-- Q & A - UtterAccess.com Forums|-- Q & A - Access Wiki Options TotakekeView Member Profile Jan 23 2011, 01:33 AM Post#1Posts: 209Joined: 14-October 10I'm not sure what I need to do, I already set the Outlook references in the options but it still doesn't work and I think it has something to do with Access 2010 because some sample databases I've tried triggers the same error too. The line in question that triggers the error in the code below is
am successfully sending emails through Outlook from Access. Initially it seemed that there was no need for Outlook to be open for me to do this. http://www.pcreview.co.uk/threads/objoutlook-createitem-olmailitem-error.2461236/ Now, however I am getting an error -2113732604 at the line Set objOutlookMsg https://bytes.com/topic/access/answers/892781-how-do-i-fix-compile-error-user-defined-type-not-defined = objOutlook.CreateItem(olMailItem) It does not occur if I have Outlook open. I would be grateful if someone could suggest what might have happened to change things such that I now have to have Outlook open to avoid this error. Thanks Reg Reg, Mar 25, 2006 #1 Advertisements TC variable not Guest What is the full text of the error? Show us the surrounding code. It's hard to comment, from just one line. TC (MVP Access) http://tc2.atspace.com TC, Mar 25, 2006 #2 Advertisements Reg Guest "TC" <> wrote in message news:... > What is the full text of the error? > > Show us the surrounding code. It's hard to comment, from just object variable or one line. > > TC (MVP Access) > http://tc2.atspace.com > Thank you - here it is: Sub sbSendMessage(Optional AttachmentPath) '' from http://msdn.microsoft.com/library/default.asp?url=/library/en-us/dno2k3ta/html/odc_ac_olauto.asp Dim objOutlook As Outlook.Application Dim objOutlookMsg As Outlook.MailItem Dim objOutlookRecip As Outlook.Recipient Dim objOutlookAttach As Outlook.Attachment On Error GoTo ErrorMsgs ' Create the Outlook session. Set objOutlook = CreateObject("Outlook.Application") ' Create the message. This next line is the one at which I get the eror message Set objOutlookMsg = objOutlook.CreateItem(olMailItem) With objOutlookMsg ' Add the To recipient(s) to the message. Set objOutlookRecip = .Recipients.Add(txtTo) objOutlookRecip.Type = olTo ' Add the CC recipient(s) to the message. If Not txtCC = "" Then Set objOutlookRecip = .Recipients.Add(txtCC) objOutlookRecip.Type = olCC End If If Not txtBCC = "" Then Set objOutlookRecip = .Recipients.Add(txtBCC) objOutlookRecip.Type = olBCC End If ' Set the Subject, Body, and Importance of the message. .Subject = txtSubject .Body = txtBody & vbCrLf & vbCrLf .Importance = olImportanceNormal ' Add attachments to the message. If Len(attachmentfile1) > 2 Then Set objOutlookAttach = .Attachments.Add(attachmentfile1) End If If Len(attachmentfile2) > 2 Then Set objOutlookAttach = .Attachments.Add(attachmentfile2) End If If Len(attachmentfile3) > 2 Then Set objOutlookAttac
+ Ask a Question Need help? Post your question and get tips & solutions from a community of 418,558 IT Pros & Developers. It's quick & easy. How do I fix Compile Error: User-defined type not defined? P: 4 travjbad1 I am new to the forum and new to Access, so please be simple and descriptive if possible. I am having a problem with a button on a form that saves, opens a report in pdf, and emails the report to the client. I believe the email is what is failing. I get the Error message "Compile Error: User-defined type not defined" and this is the section of code that pops up: Expand|Select|Wrap|Line Numbers PublicFunctionSendClientEmail(emailtoAsVariant,attachmentpathAsVariant,subjectmsgAsString,msgAsString,Optionalattachmentpath2AsVariant) OnErrorGoToSendClientEmail_Err DimappOutLookAsOutlook.Application DimMailOutLookAsOutlook.MailItem SetappOutLook=CreateObject("Outlook.Application") SetMailOutLook=appOutLook.CreateItem(olMailItem) The "Dim appOutLook As Outlook.Application" portion is highlighted in blue and highlighted in yellow is the first line "Public Function SendClientEmail(emailto As Variant, attachmentpath As Variant, subjectmsg As String, msg As String, Optional attachmentpath2 As Variant)" Can anyone walk me through how to fix this error? I appreciate any help I can get. Aug 4 '10 #1 Post Reply Share this Question 6 Replies Expert 100+ P: 610 MikeTheBike Hi If you want to use late binding (as you are if you are using CreatObject()) then you should dimension the variable like this Expand|Select|Wrap|Line Numbers DimappOutLookAsObject DimMailOutLookAsObject If you want to use early binding then you need to set a reference to the Microsoft Outlook 11.0 Object Library (Tools->References when in a VBA Module). This, I believe, is why you are getting the error. ie. code like this Expand|Select|Wrap|Line Numbers DimappOutLookAsOutlook.Application DimMailOutLookAsOutlook.MailItem SetappOutLook=NewOutlook.Application SetMailOutLook=NewOutlook.MialIten HTH But don't ask me how to use these object because I never have (not yet anyway!) MTB Aug 6 '10 #2 reply Expert Mod 15k+ P: 29,922 NeoPa Any code using objects from another application (in this case Outlook) must ensure that the relevant libraries are referenced otherwise the compiler will not understand the context and give you the error you got. I think Application Automation gives you what you need for this. If there is anything missing let me know. BTW, Mike was essentially right in what he was saying too. Welcome to Bytes! Aug 6 '10 #3 reply P: 4 travjbad1 Thanks for the help. Just in case someone else has the same problem here is another