Accessing Field2 in Access 2007

浪子不回头ぞ 提交于 2020-01-11 07:39:08

问题


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?


回答1:


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"




回答2:


Change the line to

 Dim attachmentField As DAO.Field

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



来源:https://stackoverflow.com/questions/1196960/accessing-field2-in-access-2007

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!