By using this site, you agree to our updated Privacy Policy and our Terms of Use. Manage your Cookies Settings.
446,293 Members | 1,302 Online
Bytes IT Community
+ Ask a Question
Need help? Post your question and get tips & solutions from a community of 446,293 IT Pros & Developers. It's quick & easy.

[ask] Import Data From Ms Word To Ms Access Via Macro

P: 3
hi, i'm trying to make macro in ms word..
the idea is ...
everytime i push/select save button in ms word, the name and path of current document will automaticly saved to ms access...

this far.. i already succeed to make this macro triggered every time i select "save" on ms word, but about the data .. failed !
i can't append/add the data to ms access.

please help me..
thanks before
Sep 3 '07 #1
Share this Question
Share on Google+
5 Replies


FishVal
Expert 2.5K+
P: 2,653
hi, i'm trying to make macro in ms word..
the idea is ...
everytime i push/select save button in ms word, the name and path of current document will automaticly saved to ms access...

this far.. i already succeed to make this macro triggered every time i select "save" on ms word, but about the data .. failed !
i can't append/add the data to ms access.

please help me..
thanks before
Hi, there.

You can establish connection with database from word document and add new record to a table via recordset or SQL command.
Sep 3 '07 #2

P: 3
Hi, there.

You can establish connection with database from word document and add new record to a table via recordset or SQL command.

yup... thx for your help.
i'm still wondering, how this SQL statement is writen into my macro.. please correct my macro below ( because every time i try it.... pop up error always occur )

Dim db As DAO.Database
Dim rst As DAO.Recordset
Dim strSQL As String
Dim strPath As String
Dim Doc As Document

Set Doc = ThisDocument
strSQL = "INSERT INTO TPath ( Nama, Path, Keterangan ) VALUES (Tes3, TesPath3, KeteranganPath3)"

strPath = "C:/Access/myDB.mdb"

'Update path to database file.

Set db = OpenDatabase(strPath)
Set rst = db.OpenRecordset(strSQL)

Set db = Nothing
Set rst = Nothing

=================================

this day... i know (maybe) the problem is "set rst = db.OpenRecordset(strSQL)"
... so i change it to "set rst = db.Execute(strSQL)"

but the error is still occured... can u help me, please ?
Sep 3 '07 #3

FishVal
Expert 2.5K+
P: 2,653
yup... thx for your help.
i'm still wondering, how this SQL statement is writen into my macro.. please correct my macro below ( because every time i try it.... pop up error always occur )

Dim db As DAO.Database
Dim rst As DAO.Recordset
Dim strSQL As String
Dim strPath As String
Dim Doc As Document

Set Doc = ThisDocument
strSQL = "INSERT INTO TPath ( Nama, Path, Keterangan ) VALUES (Tes3, TesPath3, KeteranganPath3)"

strPath = "C:/Access/myDB.mdb"

'Update path to database file.

Set db = OpenDatabase(strPath)
Set rst = db.OpenRecordset(strSQL)

Set db = Nothing
Set rst = Nothing

=================================

this day... i know (maybe) the problem is "set rst = db.OpenRecordset(strSQL)"
... so i change it to "set rst = db.Execute(strSQL)"

but the error is still occured... can u help me, please ?
  • Make sure DAO library is referenced
  • db.Execute(strSQL) is right approach for action query, but to the best of my knowledge it doesn't return recordset and for action query recordset is not expected to be returned

BTW, here is an example of working code updating table via recordset
"Microsoft ActiveX Data Object x.x Library" has to be referenced.
Expand|Select|Wrap|Line Numbers
  1. Private Sub CommandButton1_Click()
  2.  
  3.     Dim con As New ADODB.Connection
  4.     Dim rs As New ADODB.Recordset
  5.  
  6.     With con
  7.         .ConnectionString = "Provider=Microsoft.jet.oledb.4.0;" & _
  8.             "Data Source=X:\db1.mdb"
  9.         .Open
  10.     End With
  11.  
  12.     With rs
  13.         .Open "tblPaths", con, adOpenDynamic, adLockOptimistic
  14.         .AddNew
  15.         ![txtPath] = ThisDocument.Path
  16.         ![txtName] = ThisDocument.Name
  17.         .Update
  18.         .Close
  19.     End With
  20.  
  21.     con.Close
  22.  
  23.     Set rs = Nothing
  24.     Set con = Nothing
  25.  
  26. End Sub
  27.  
Sep 3 '07 #4

P: 3
yup... i have tried your code... it worked... :)
so glad.....

right now, i can add what i need to this code... thank you very much..

the problem is solved.....
Sep 3 '07 #5

FishVal
Expert 2.5K+
P: 2,653
yup... i have tried your code... it worked... :)
so glad.....

right now, i can add what i need to this code... thank you very much..

the problem is solved.....
You are welcome.
Good luck.
Sep 3 '07 #6

Post your reply

Sign in to post your reply or Sign up for a free account.