Search

VBA to Upload Files to Access Database as Attachment

VBA to Upload Files to Access Database as Attachment - New Video

Option Compare Database
Option Explicit

Sub upload_file_from_excel_to_access_db()

Dim db As DAO.Database
Dim ws As DAO.Workspace

Dim rst As DAO.Recordset
Dim attachFld As DAO.Recordset

Set ws = DBEngine.Workspaces(0)
Set db = ws.OpenDatabase("D:\VBAA2Z Demo\Access VBA\Attachment Load\org_db.accdb", False, False, "MS Access;PWD=")

Set rst = db.OpenRecordset("SELECT * FROM AttachmentDemotb;", dbOpenDynaset)

rst.AddNew
  
  rst!Title = "Test from Access-4"
  
  Set attachFld = rst.Fields("Attachements").Value
  
  attachFld.AddNew
    attachFld.Fields("FileData").LoadFromFile "D:\VBAA2Z Demo\Access VBA\Attachment Load\flows_report.pdf"
  attachFld.Update
  
  attachFld.AddNew
    attachFld.Fields("FileData").LoadFromFile "D:\VBAA2Z Demo\Access VBA\Attachment Load\plugandplay.JPG"
  attachFld.Update
  
  
rst.Update

rst.Close
db.Close
ws.Close

Set rst = Nothing
Set attachFld = Nothing
Set db = Nothing
Set ws = Nothing

End Sub

No comments:

Post a Comment

Note: only a member of this blog may post a comment.