I’m trying to make VBA script for Access 2013 which will help to process Word 2013 forms from folder, attach these files of Word 2013 form to relevant record entry and attach pdf file from same folder with the same name.
Word form made with simple "text field" (i.e. not ActiveX text field)
Since I’m not a programmer each try leads me to next error. Can anyone help to make it work.
Thanks.
I’ve found a sample of «attach script”, however I don’t have a clue how to insert into logic of whole algorithm.
Word form made with simple "text field" (i.e. not ActiveX text field)
Since I’m not a programmer each try leads me to next error. Can anyone help to make it work.
Thanks.
Code:
Dim appWord As Word.Application
Dim doc As Word.Document
Dim db As Database
Dim SourceFolderPath As String, DestinationFolderPath As String, FormFile As String
Dim FSO As Object, FileInSourceFolderPath As Object
Dim rst As dao.Recordset
Dim blnQuitWord As Boolean
SourceFolderPath = CurrentProject.Path & "\DATA\"
DestinationFolderPath = CurrentProject.Path & "\TEMP\"
FormFile = Dir(SourceFolderPath & "\*.docx")
Set appWord = GetObject(, "Word.Application")
Set doc = appWord.Documents.Open(FormFile)
CurrentDb.OpenRecordset "FormData"
With rst
.AddNew
!Question1 = doc.FormFields("Q1").Result
!Question2 = doc.FormFields("Q2").Result
!Question3 = doc.FormFields("Q3").Result
.Update
.Close
End With
doc.Close
If blnQuitWord Then appWord.Quit
Set FSO = CreateObject("scripting.filesystemobject")
For Each FileInSourceFolderPath In FSO.getfolder(SourceFolderPath).Files
FileInSourceFolderPath.Move DestinationFolderPath
Next FileInSourceFolderPath
MsgBox "Forms imported!"
I’ve found a sample of «attach script”, however I don’t have a clue how to insert into logic of whole algorithm.
Code:
Dim cdb As DAO.Database, rstMain As DAO.Recordset, rstAttach As DAO.Recordset2, _
fldAttach As DAO.Field2
Set cdb = CurrentDb
Set rstMain = cdb.OpenRecordset("SELECT MyFilePath, MyFileAttach FROM tblTest", dbOpenDynaset)
Do Until rstMain.EOF
rstMain.Edit
Set rstAttach = rstMain("MyFileAttach").Value
rstAttach.AddNew
Set fldAttach = rstAttach.Fields("FileData")
fldAttach.LoadFromFile rstMain("MyFilePath").Value
rstAttach.Update
rstAttach.Close
Set rstAttach = Nothing
rstMain.Update
rstMain.MoveNext
Loop
rstMain.Close
Set rstMain = Nothing
Set cdb = Nothing