Question

I'm trying to write a simple little routine to email an attachment stored in an Access 2007 database. For some reason I cannot get the simplest part of it to work.

I get an error saying "User-defined type not defined" on the following line:

Dim attachmentField As DAO.Field2

Now up to this point I haven't accessed any DAO objects yet, but my assumption was that I only needed to add the relevant reference. Thing is, I seem to have a misconception about what that reference is. I have tried "Microsoft DAO 3.6 Object Library" which made sense, but I'm still getting the same error message. Then I tried 3.5 of the same and then JET and then a few more that made far less sense.

Here's the full listing, in case I missed something else that is real basic. I know it needs an awful lot of cleanup, but I'd like to get it working first.

Private Sub Command4_Click()
  Dim appOutLook As Outlook.Application
  Dim MailOutLook As Outlook.MailItem
  Set appOutLook = CreateObject("Outlook.Application")
  Set MailOutLook = appOutLook.CreateItem(olMailItem)

  With MailOutLook
    .To = Description.Value
    .Subject = "Confirmation of " & ID.Value

    'Error on the next line
    Dim attachmentField As DAO.Field2
    attachmentField = Recordset("Att")
    attachmentField.SaveToFile "C:\Temp\" & Att.FileName
    Attachments.Add "C:\Temp\" & Att.FileName, olByValue, 1, "Document"

    '.DeleteAfterSubmit = True
    .Send
  End With
End Sub

Any ideas?

Was it helpful?

Solution

You need a reference to DAO Version 12 - which supports the new FIELD2 object

Try adding this reference - "Microsoft Office 12.0 Access database engine"

OTHER TIPS

Change the line to

 Dim attachmentField As DAO.Field

Also, where does the Recordset come from? Where is it being filled with records?

Licensed under: CC-BY-SA with attribution
Not affiliated with StackOverflow
scroll top