By using this site, you agree to our updated Privacy Policy and our Terms of Use. Manage your Cookies Settings.
432,306 Members | 1,657 Online
Bytes IT Community
+ Ask a Question
Need help? Post your question and get tips & solutions from a community of 432,306 IT Pros & Developers. It's quick & easy.

How do I fix Compile Error: User-defined type not defined?

P: 4
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
  1. Public Function SendClientEmail(emailto As Variant, attachmentpath As Variant, subjectmsg As String, msg As String, Optional attachmentpath2 As Variant)
  2. On Error GoTo SendClientEmail_Err
  3.     Dim appOutLook As Outlook.Application
  4.     Dim MailOutLook As Outlook.MailItem
  5.     Set appOutLook = CreateObject("Outlook.Application")
  6.     Set MailOutLook = 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
Share this Question
Share on Google+
6 Replies


Expert 100+
P: 634
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
  1. Dim appOutLook As Object
  2. Dim MailOutLook As Object
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
  1.     Dim appOutLook As Outlook.Application
  2.     Dim MailOutLook As Outlook.MailItem
  3.  
  4.     Set appOutLook = New Outlook.Application
  5.     Set MailOutLook = New Outlook.MialIten
HTH

But don't ask me how to use these object because I never have (not yet anyway!)

MTB
Aug 6 '10 #2

NeoPa
Expert Mod 15k+
P: 31,474
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

P: 4
Thanks for the help. Just in case someone else has the same problem here is another way to solve it. Open up Microsoft Visual Basic > open Tools > References. Then just make sure the program you were trying to use, in this case Outlook is checked. In my case someone got into the Visual Basic and accidentally unchecked it. Thanks for the help everyone.
Aug 10 '10 #4

NeoPa
Expert Mod 15k+
P: 31,474
That's not so much another way of doing it, as a repetition of what was said in both of the previous posts. Would it be fair to say you didn't understand what was being said?
Aug 10 '10 #5

P: 4
Whoops! I didn't read very carefully. You're right. I got help last week before someone had time to post something here and I thought I'd just come in and say thanks. I'm new so I thought I'd provide something in simple terms that someone like me could understand. Like I said thank you for the help though.
Aug 10 '10 #6

NeoPa
Expert Mod 15k+
P: 31,474
That's fine :)

Actually, it does help sometimes for things to be stated in simpler English (which is why I was worried you hadn't understood). I suspect there are occasions when we give perfect answers, except in the respect that some people find them hard to understand. We live and learn.
Aug 10 '10 #7

Post your reply

Sign in to post your reply or Sign up for a free account.