在Access 2007中访问字段2字段、Access

2023-09-08 11:12:35 作者:落笔映惆怅丶

我试着写一个简单的小程序的电子邮件存储在Access 2007数据库的附件。出于某种原因,我不能得到它的最简单的部分工作。

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

现在到这一点我没有访问的任何DAO对象还没有,但我的假设是,我只需要添加相应的参考。事情是,我似乎有一个关于什么参考的误解。我曾尝试Microsoft DAO 3.6对象库,这是有道理的,但我仍然得到同样的错误消息。然后我试图3.5相同的,然后JET,然后几个,使得远不如感。

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

任何想法?

推荐答案

您需要引用DAO 12版 - 支持新FIELD2对象

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

尝试添加此引用 - 微软的Office 12.0 Access数据库引擎

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