انظر الصورة المرفقة للتأكد .
لذالك ، وتحقيقاً لنفس الفكرة من زر Open .. استخدمت الدالة التالية :-
Public Sub OpenAttachmentFile(ByVal RecordID As Long, Optional ByVal PKFieldName As String = "ID")
Dim rs As DAO.Recordset
Dim rst As DAO.Recordset2
Dim filePath As String
Dim cachePath As String
Dim subFolder As String
cachePath = Environ("LOCALAPPDATA") & "\Microsoft\Windows\INetCache\"
Randomize
subFolder = "ACC" & Int((9999 * Rnd) + 1)
If Dir(cachePath & subFolder, vbDirectory) = "" Then
MkDir cachePath & subFolder
End If
Set rs = CurrentDb.OpenRecordset("SELECT progIcon FROM tblEnDc WHERE " & PKFieldName & "=" & RecordID)
Set rst = rs.Fields("progIcon").Value
If Not rst.EOF Then
filePath = cachePath & subFolder & "\" & rst.Fields("FileName").Value
If Dir(filePath) = "" Then
rst.Fields("FileData").SaveToFile filePath
End If
FollowHyperlink filePath
End If
rst.Close: Set rst = Nothing
rs.Close: Set rs = Nothing
End Sub
واستدعيها حسب رقم السجل من خلال الزر كما يلي :-
Call OpenAttachmentFile(Me.ID)
طبعاً اسم المجلد عشوائي لمحاكاة نفس اسلوب آكسيس في السطر
subFolder = "ACC" & Int((9999 * Rnd) + 1)