VBA Code won't Compile

Collapse
X
 
  • Time
  • Show
Clear All
new posts
  • DJRhino1175
    New Member
    • Aug 2017
    • 221

    VBA Code won't Compile

    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.

    Code:
    Option Compare Database
    Option Explicit
    
    Private Sub E_Mail_Daily_Report_Click()
    
    Dim strEMail As String
    Dim oOutlook As Object
    Dim oMail As Object
    Dim strAddr As String
    Dim MyDB As DAO.Database
    Dim rstEMail As DAO.Recordset
    Dim strReportName As String
    
    Set oOutlook = CreateObject("Outlook.Application")
    Set oMail = oOutlook.CreateItem(0)
    
    strReportName = "RptDailyReport"
    
    DoCmd.OutputTo acOutputReport, "RptDailyReport", acFormatPDF, CurrentProject.Path & _
                   "\" & strReportName & ".pdf", False, , , acExportQualityPrint
     
    'Retrieve all E-Mail Addresses in tblEMailAddress
    Set MyDB = CurrentDb
    Set rstEMail = MyDB.OpenRecordset("Select * From TblEmail", dbOpenSnapshot, dbOpenForwardOnly)
     
    With rstEMail
      Do While Not .EOF
        'Build the Recipients String
        strEMail = strEMail & ![EmailAddress] & ";"
          .MoveNext
      Loop
    End With
    '--------------------------------------------------
     
    With oMail
      .To = Left$(strEMail, Len(strEMail) - 1)        'Remove Trailing ;
      .Body = "Please review the attached report."
      .Subject = "Daily Retest Report"
        .Display
      .Attachments.Add CurrentProject.Path & "\" & strReportName & ".pdf"
      
    End With
     
    Set oMail = Nothing
    Set oOutlook = Nothing
     
    rstEMail.Close
    Set rstEMail = Nothing
    
    Dim aFile As String
    aFile = "N:\Lab\Underwater Retest Daily Reports\Daily Report.pdf"
    If Len(Dir$(aFile)) > 0 Then
         Kill aFile
    End If
    
    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.
  • Seth Schrock
    Recognized Expert Specialist
    • Dec 2010
    • 2965

    #2
    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.

    Comment

    • DJRhino1175
      New Member
      • Aug 2017
      • 221

      #3
      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.

      Comment

      • NeoPa
        Recognized Expert Moderator MVP
        • Oct 2006
        • 32633

        #4
        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.

        Comment

        Working...