J
Jeff Kunberger
Currently I have a module that pulls data fields from a locked Word form.
However, I need to also be able to update (not add a new record) from a
different Word Form.
The "header" of the code is thus:
-------------------------------------------
Sub GetWordData()
Dim appWord As Word.Application
Dim doc As Word.Document
Dim cnn As New ADODB.Connection
Dim rst As New ADODB.Recordset
Dim strDocName As String
Dim blnQuitWord As Boolean
Dim strFileName As String
Dim docOpenedFile As Document
On Error GoTo ErrorHandling
Const FILE_PATH As String = "R:\Internal Audit\Security Admin\Risk
Assessment Database\"
strFileName = Dir(FILE_PATH)
Do Until strFileName = ""
If Not ((strFileName = ".doc")) Then
If Not GetAttr(FILE_PATH & strFileName) = vbDirectory Then
Set appWord = GetObject(, "Word.Application")
Set doc = appWord.Documents.Open(FILE_PATH & strFileName)
cnn.Open "Provider=Microsoft.Jet.OLEDB.4.0;" & _
"Data Source= R:\Internal Audit\Security Admin\Risk Assessment
Database\Risk\" & _
"Risk Assessment.mdb;"
rst.Open "tblRiskAssesment", cnn, _
adOpenKeyset, adLockOptimistic
------------------------------------------------------------
And the body of the code is below with each field being preceded by a !
----------------------------------------------------------
With rst
.AddNew
!UserGroup = doc.FormFields("Dropdown1").Result
!SystemName = doc.FormFields("Dropdown2").Result
---------------------------------------------------------------
I messed around with deleting the ".Add New" at the begining of the body and
the "Dim rst As New ADODB.Recordset" from the header, but can't get the
records to overwrite in the table.
Any ideas on how to tweak the existing code so if it finds a !UserGroup that
has already been defined, it just writes over with the existing data from the
Word Form?
Thanks in advance for all your help
However, I need to also be able to update (not add a new record) from a
different Word Form.
The "header" of the code is thus:
-------------------------------------------
Sub GetWordData()
Dim appWord As Word.Application
Dim doc As Word.Document
Dim cnn As New ADODB.Connection
Dim rst As New ADODB.Recordset
Dim strDocName As String
Dim blnQuitWord As Boolean
Dim strFileName As String
Dim docOpenedFile As Document
On Error GoTo ErrorHandling
Const FILE_PATH As String = "R:\Internal Audit\Security Admin\Risk
Assessment Database\"
strFileName = Dir(FILE_PATH)
Do Until strFileName = ""
If Not ((strFileName = ".doc")) Then
If Not GetAttr(FILE_PATH & strFileName) = vbDirectory Then
Set appWord = GetObject(, "Word.Application")
Set doc = appWord.Documents.Open(FILE_PATH & strFileName)
cnn.Open "Provider=Microsoft.Jet.OLEDB.4.0;" & _
"Data Source= R:\Internal Audit\Security Admin\Risk Assessment
Database\Risk\" & _
"Risk Assessment.mdb;"
rst.Open "tblRiskAssesment", cnn, _
adOpenKeyset, adLockOptimistic
------------------------------------------------------------
And the body of the code is below with each field being preceded by a !
----------------------------------------------------------
With rst
.AddNew
!UserGroup = doc.FormFields("Dropdown1").Result
!SystemName = doc.FormFields("Dropdown2").Result
---------------------------------------------------------------
I messed around with deleting the ".Add New" at the begining of the body and
the "Dim rst As New ADODB.Recordset" from the header, but can't get the
records to overwrite in the table.
Any ideas on how to tweak the existing code so if it finds a !UserGroup that
has already been defined, it just writes over with the existing data from the
Word Form?
Thanks in advance for all your help