将文件拖放到Microsoft Access中 [英] Drag and Drop File into Microsoft Access

查看:131
本文介绍了将文件拖放到Microsoft Access中的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我在Microsoft Access中有一个表单,允许用户将附件上载到每个记录。我想让用户将文件拖放到附件字段中,以使其对用户更加友好。最好的方法是什么/如何做?

I have a form in Microsoft Access which lets users upload attachments to each record. I'd like to make it a little user friendly by letting users drag and drop files into the attachment field. What is the best way of doing this/how do I do this?

推荐答案

这里是一种拖放附加文件以用于MS Access数据库的方法。

Here is a way to drag and drop "attached" files for use with MS Access database.

(当前使用Office 365版本1811)
MS Access当前允许拖放到超链接字段。
使用此功能,此示例允许拖放以将附件文件存储到存储位置,同时保留到原始位置和新位置的链接。当将文件放入表单的 HyperlinkIn框中或以常规方式更改超链接时,将运行该事件。

(Currently using Office 365 Version 1811) MS Access currently allows drag and drop to a hyperlink field. Using this capability this example allows drag and drop to store an attachment file to a storage location while keeping a link to the original and new locations. The event runs when a file is dropped into the HyperlinkIn box on the form or when the hyperlink is changed the normal way.

由于2GB的限制,最好将文件存储在带有链接的存储位置中,而不是将其存储在.accdb文件中。您可以将其称为数据库+文件服务器体系结构。通过使用记录号以及(可选)数据库和表名以及附件号,可以确保文件名唯一。

It is better to store the file in a storage location with a link than to store it within the .accdb file due to the 2GB limitation. You might call this a database + file server architecture. By using the record number and optionally the database and table name and attachment number you can ensure unique file names.

制作具有3个字段的表格和表单。
ID(自动编号)
HyperlInkIN(超链接)
HyperLinkOUT(超链接)

Make a Table and Form with 3 fields. ID (AutoNumber) HyperlInkIN (hyperlink) HyperLinkOUT (hyperlink)

为此HyperLinkIn表单的AfterUpdate事件插入此VBS代码

Insert this VBS code for AfterUpdate event for the HyperlinkIn form control.

Private Sub HyperlinkIN_AfterUpdate()
Dim InPath As String
Dim FileName As String
Dim OutFolder As String
Dim OutPath As String
Dim RecordNo As String
Dim FileExt As String


OutFolder = "\\networkdrive\vol1\attachments\"  'specify the output folder  

InPath = Me!HyperlinkIN.Hyperlink.Address
RecordNo = Me!ID

If Len(InPath) > 0 Then
    FileName = Right(InPath, Len(InPath) - InStrRev(InPath, "\"))  'get the file name
    FileExt = Right(FileName, Len(FileName) - InStrRev(FileName, ".") + 1) ' get the file extension with dot

'build the new path with output folder path and record number and date and extension
        OutPath = OutFolder & "Record " & RecordNo & " Attachment " & Format(Now(), "ddmmmyy") & FileExt 

    FileCopy InPath, OutPath

    Me!HyperlinkOUT = "#" & OutPath & "#"  

    MsgBox "Copied file to archives   " & vbCrLf & InPath & vbCrLf & OutPath
End If

End Sub

我有点经验不足使用vba,因此可能会有一些更好的方法来确保和验证成功的文件副本,但是此示例对我有用,对我来说很容易理解。我使用MsgBox帮助调试了注释掉的实际文件副本。

I am somewhat inexperienced with vba so there may be some better ways to ensure and verify a successful file copy but this example works for me and is easy for me to understand. I used the MsgBox to help debug with the actual file copy commented out.

这篇关于将文件拖放到Microsoft Access中的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆