"User-Defined Type Not Defined" Error Message

I'm struggling with the simplest thing.  Just trying to send emails from an Access query.  Looked at half a dozen examples (of work I've already used), but keep getting "User-Defined Type Not Defined" Error Message.
Public Sub EmailDistribution()
Dim db As Database
Set db = CurrentDb
Dim ol As Outlook.Application
Dim olMail As Outlook.MailItem
Dim qdf As QueryDef
Dim rst As DAO.Recordset
Set qdf = db.QueryDefs("EmailToQ")
Set rst = qdf.OpenRecordset()
rst.MoveFirst

While Not rst.EOF
  
  Set olMail = ol.CreateItemFromTemplate("C:\\\\*.oft")

  With olMail
     .To = rst!Email
     '.CC = ""
     '.BCC = ""
     '.Attachments.Add "c:\file1.txt"
     '.Attachments.Add "c:\file2.txt"
     .Subject = rst!Subject
     .Body = rst!Description
      
     .Send
  End With
  rst.MoveNext
  
  
Wend

Set olMail = Nothing
Set ol = Nothing

End Sub

Open in new window

What am I missing?  I would like each email to go out in 1 minute intervals. Thanks
Jay WilliamsOwnerAsked:
Who is Participating?
I wear a lot of hats...

"The solutions and answers provided on Experts Exchange have been extremely helpful to me over the last few years. I wear a lot of hats - Developer, Database Administrator, Help Desk, etc., so I know a lot of things but not a lot about one thing. Experts Exchange gives me answers from people who do know a lot about one thing, in a easy to use platform." -Todd S.

Rey Obrero (Capricorn1)Commented:
in the vba window
Tools > References make sure that there are no "MISSING" references

do a DEBUG > Compile
correct any errors raised

when you get the error, which item/line is highlighted?

it is also a good practice to add "Option Explicit" to your module
0
Jay WilliamsOwnerAuthor Commented:
Thanks!  Don't you ever take a day off, Rey? :-) I should have thought of that. This is a new rig, and I selected "Microsoft Office" references instead of "Microsoft Outlook."  No bugs now, but I still would like to space those emails out a little. Any thoughts?
0
Rey Obrero (Capricorn1)Commented:
you can try using the Sleep function,
add this line on top of a regular module

Private Declare Sub Sleep Lib "kernel32" (ByVal lngMilliSeconds As Long)

to use, place  inside your code loop

    Sleep 100  'change the value of 100 accordingly
    DoEvents
0

Experts Exchange Solution brought to you by

Your issues matter to us.

Facing a tech roadblock? Get the help and guidance you need from experienced professionals who care. Ask your question anytime, anywhere, with no hassle.

Start your 7-day free trial
It's more than this solution.Get answers and train to solve all your tech problems - anytime, anywhere.Try it for free Edge Out The Competitionfor your dream job with proven skills and certifications.Get started today Stand Outas the employee with proven skills.Start learning today for free Move Your Career Forwardwith certification training in the latest technologies.Start your trial today
Microsoft Access

From novice to tech pro — start learning today.

Question has a verified solution.

Are you are experiencing a similar issue? Get a personalized answer when you ask a related question.

Have a better answer? Share it in a comment.