Access 2007 Error: Compile error: User-defined type not defined

epoling

New member
Local time
Today, 06:01
Joined
Dec 29, 2010
Messages
3
I am brand new to Access 2007. I am presently attempting to migrate from 2003 to 2007. My current 2003 database sends e-mails when a button is clicked. The e-mails gather information from the form. This works just fine in 2003. I am getting the error message "Compile error: User defined type not defined."

The debugger highlights the code "Dim objOutlook As Outlook.Application"

I am including an excerpt of the code here:

Private Sub ReqHomeDrive_Click()
On Error GoTo Err_ReqHomeDrive_Click
Dim strstrEmail, strBody As String, strSubject As String, strHPBody As String
Dim strAdm As String
Dim objOutlook As Outlook.Application
Dim objEmail As Outlook.MailItem
Dim strTo As String
Dim AddlInfo As String
Dim Sent4Info As String
Dim InfoRequestSentDate As String
Dim strAppAccess As String
Dim strEmplID As String
Dim strServer As String
Dim ReqDate
ReqDate = Date
------------

I am a novice at VBA and need your help. Anything you can do to help me find out why this is considered a user-defined function and not an imbedded function within Access would be greatly appreciated. I've read some of the posts here and see that line is used, apparently successfully.

Regards,
Ernestine
 
You would have to go to TOOLS > REFERENCES in the VBA window and set a reference to Microsoft Outlook. However, that can be a problem if you have different versions around. If you want it to always work regardless of which version, change to late binding and change your code to

Code:
Private Sub ReqHomeDrive_Click()
    On Error GoTo Err_ReqHomeDrive_Click
    Dim strstrEmail, strBody As String, strSubject As String, strHPBody As String
    Dim strAdm As String
    Dim objOutlook As [B][COLOR=red]Object[/COLOR][/B]
    Dim objEmail As [B][COLOR=red]Object[/COLOR][/B]
    Dim strTo As String
    Dim AddlInfo As String
    Dim Sent4Info As String
    Dim InfoRequestSentDate As String
    Dim strAppAccess As String
    Dim strEmplID As String
    Dim strServer As String
    Dim ReqDate
    
    ReqDate = Date

And then where you instantiate the objOutlook use

Set objOutlook = CreateObject("Outlook.Application")
 
What Bob Larson is telling you is most certainly true. Late binding does make programming a little more difficult though since you won't have intellisense to help you out as you try to determine how to access certain properties.

I also have code that uses Outlook to send emails but I always use late binding so that the users can have (almost) any version of Outlook and it will still work OK.
 
Bob, thanks so much for your quick response. I haven't had a chance to try it out but will do so.

Question, admitting I'm a novice, what do you mean by "late binding?"

Thanks again!

E

PS Editing this post. We all use same version of Outlook so I took the shortcut and added the Reference. Works like a charm!!! So glad I found this forum today!

I still want to understand late binding though.
 
Last edited:
Bob, thanks so much for your quick response. I haven't had a chance to try it out but will do so.

Question, admitting I'm a novice, what do you mean by "late binding?"

Thanks again!

E

Early Binding is where you, at design time, set a reference in the VBA references to something (in this case the Microsoft Outlook XX.0 Object Library - where XX is like 10 for Outlook 2000, 11 for 2002-2003, 12 for 2007 and 14 for 2007) and then you can use, as HK1 has said, Intellisense to be able to display methods and properties as you code by pressing the period and then the available options drop down. I usually will CODE with Early Binding but convert to Late Binding (where you don't set a reference and you declare your objects as OBJECT instead of the actual object type and the program interprets it at run time).
 
Thanks Bob, I think I understand it. Will keep this in mind for later. Meanwhile, just glad that I have the thing working!!! Now on to the next...

Have never posted in a forum before and this really has been a wonderful experience.
 

Users who are viewing this thread

Back
Top Bottom