469,280 Members | 1,959 Online
Bytes | Developer Community
New Post

Home Posts Topics Members FAQ

Post your question to a community of 469,280 developers. It's quick & easy.

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

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
6 19344
637 Expert 512MB

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
  4.     Set appOutLook = New Outlook.Application
  5.     Set MailOutLook = New Outlook.MialIten

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

Aug 6 '10 #2
32,172 Expert Mod 16PB
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
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
32,172 Expert Mod 16PB
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
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
32,172 Expert Mod 16PB
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.

Similar topics

4 posts views Thread by Danny Boelens | last post: by
1 post views Thread by Tony Johansson | last post: by
reply views Thread by Tony Johansson | last post: by
2 posts views Thread by Tony Johansson | last post: by
10 posts views Thread by Chris LaJoie | last post: by
reply views Thread by Jim Heavey | last post: by
2 posts views Thread by Schwack | last post: by
1 post views Thread by CARIGAR | last post: by
reply views Thread by zhoujie | last post: by
reply views Thread by suresh191 | last post: by
By using this site, you agree to our Privacy Policy and Terms of Use.