在 Access 2007 中访问 Field2
我正在尝试编写一个简单的小例程来通过电子邮件发送存储在 Access 2007 数据库中的附件。 由于某种原因,我无法使其最简单的部分发挥作用。
我在以下行中收到一条错误消息“用户定义的类型未定义”:
Dim attachmentField As DAO.Field2
现在到目前为止,我还没有访问任何 DAO 对象,但我的假设是我只需要添加相关引用。 问题是,我似乎对那个参考是什么有误解。 我尝试过“Microsoft DAO 3.6 Object Library”,这是有道理的,但我仍然收到相同的错误消息。 然后我尝试了 3.5 个相同的版本,然后是 JET,然后又尝试了一些毫无意义的版本。
这是完整的列表,以防我错过了其他真正基本的东西。 我知道它需要大量的清理工作,但我想先让它工作。
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
有任何想法吗?
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?
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(2)
您需要对 DAO 版本 12 的引用 - 它支持新的 FIELD2 对象
尝试添加此引用 - “Microsoft Office 12.0 Access 数据库引擎”
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"
将该行更改为
另外,记录集来自哪里? 哪里充满了记录?
Change the line to
Also, where does the Recordset come from? Where is it being filled with records?