Export Form Data with MS-Access Database

  • Thread starter Charles L. Phillips
  • Start date
C

Charles L. Phillips

Hello,
I have created a form in MS-Word 97. I want to export the data in the form
to an MS-Access 97 database.
Can someone point me to an example???

Thank you,
Charles L. Phillips
 
P

Perry

Here's a simple example transfering data from Word to Access.
You'd need a pointer to the ... (Access97, hmm) that wud be: MDAC 2.1
library
The below code shud be backward compatable.

Sub SaveToAccess()
Dim cn As ADODB.Connection
Dim rs As ADODB.Recordset

'setting up the ADO connection
Set cn = New ADODB.Connection
cn.Open "Provider=Microsoft.Jet.OLEDB.4.0;" & _
"Data Source=D:\DATA\ACCESS\PERRY.mdb;"

'initializing ADO recordset
Set rs = New ADODB.Recordset
rs.Open "select Value1, Value2 from tblTest", _
cn, adOpenKeyset, adLockOptimistic

'transfer formfield results to recordset fields
With ActiveDocument.FormFields
rs.AddNew Array(rs("Value1").Name, rs("Value2").Name), _
Array(.Item("Text1").Result, .Item("Text2").Result)
rs.UpdateBatch
End With
rs.Close
cn.Close: Set cn = Nothing

End Sub

Krgrds,
Perry
 
C

Charles L. Phillips

Hello,
I'll try this out.
"Thank You"...


Perry said:
Here's a simple example transfering data from Word to Access.
You'd need a pointer to the ... (Access97, hmm) that wud be: MDAC 2.1
library
The below code shud be backward compatable.

Sub SaveToAccess()
Dim cn As ADODB.Connection
Dim rs As ADODB.Recordset

'setting up the ADO connection
Set cn = New ADODB.Connection
cn.Open "Provider=Microsoft.Jet.OLEDB.4.0;" & _
"Data Source=D:\DATA\ACCESS\PERRY.mdb;"

'initializing ADO recordset
Set rs = New ADODB.Recordset
rs.Open "select Value1, Value2 from tblTest", _
cn, adOpenKeyset, adLockOptimistic

'transfer formfield results to recordset fields
With ActiveDocument.FormFields
rs.AddNew Array(rs("Value1").Name, rs("Value2").Name), _
Array(.Item("Text1").Result, .Item("Text2").Result)
rs.UpdateBatch
End With
rs.Close
cn.Close: Set cn = Nothing

End Sub

Krgrds,
Perry
 

Ask a Question

Want to reply to this thread or ask your own question?

You'll need to choose a username for the site, which only take a couple of moments. After that, you can post your question and our members will help you out.

Ask a Question

Top