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

VBA Code won't Compile

100+
P: 120
This code has worked in multiple database I have already, but when I put it into the database I'm working on currently it will not compile.

Expand|Select|Wrap|Line Numbers
  1. Option Compare Database
  2. Option Explicit
  3.  
  4. Private Sub E_Mail_Daily_Report_Click()
  5.  
  6. Dim strEMail As String
  7. Dim oOutlook As Object
  8. Dim oMail As Object
  9. Dim strAddr As String
  10. Dim MyDB As DAO.Database
  11. Dim rstEMail As DAO.Recordset
  12. Dim strReportName As String
  13.  
  14. Set oOutlook = CreateObject("Outlook.Application")
  15. Set oMail = oOutlook.CreateItem(0)
  16.  
  17. strReportName = "RptDailyReport"
  18.  
  19. DoCmd.OutputTo acOutputReport, "RptDailyReport", acFormatPDF, CurrentProject.Path & _
  20.                "\" & strReportName & ".pdf", False, , , acExportQualityPrint
  21.  
  22. 'Retrieve all E-Mail Addresses in tblEMailAddress
  23. Set MyDB = CurrentDb
  24. Set rstEMail = MyDB.OpenRecordset("Select * From TblEmail", dbOpenSnapshot, dbOpenForwardOnly)
  25.  
  26. With rstEMail
  27.   Do While Not .EOF
  28.     'Build the Recipients String
  29.     strEMail = strEMail & ![EmailAddress] & ";"
  30.       .MoveNext
  31.   Loop
  32. End With
  33. '--------------------------------------------------
  34.  
  35. With oMail
  36.   .To = Left$(strEMail, Len(strEMail) - 1)        'Remove Trailing ;
  37.   .Body = "Please review the attached report."
  38.   .Subject = "Daily Retest Report"
  39.     .Display
  40.   .Attachments.Add CurrentProject.Path & "\" & strReportName & ".pdf"
  41.  
  42. End With
  43.  
  44. Set oMail = Nothing
  45. Set oOutlook = Nothing
  46.  
  47. rstEMail.Close
  48. Set rstEMail = Nothing
  49.  
  50. Dim aFile As String
  51. aFile = "N:\Lab\Underwater Retest Daily Reports\Daily Report.pdf"
  52. If Len(Dir$(aFile)) > 0 Then
  53.      Kill aFile
  54. End If
  55.  
  56. End Sub
Is it possible I unchecked something in the options and now it doesn't recognize something in the code?

Errors at Dim MyDB As DAO.Database

Error states:
Compile Error: User-defined type not defined.
4 Weeks Ago #1

✓ answered by Seth Schrock

Check your references to see if any are listed as missing. I believe that DAO.Database is in the Microsoft Office [version] Access Database engine object library.

Share this Question
Share on Google+
3 Replies


Seth Schrock
Expert 2.5K+
P: 2,932
Check your references to see if any are listed as missing. I believe that DAO.Database is in the Microsoft Office [version] Access Database engine object library.
4 Weeks Ago #2

100+
P: 120
That was it. I thought once I had those reference's check in access that it carried over to all databases. I guess not.

Thanks a million Seth.
4 Weeks Ago #3

NeoPa
Expert Mod 15k+
P: 31,302
Access ensures all basic databases start with some basic references, some of which you cannot even turn off.

They are all stored in the database though.

DAO is generally included by default but can be turned off.
4 Weeks Ago #4

Post your reply

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