473,438 Members | 1,717 Online
Bytes | Software Development & Data Engineering Community
Post Job

Home Posts Topics Members FAQ

Join Bytes to post your question to a community of 473,438 software developers and data experts.

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

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
5 2413
FishVal
2,653 Expert 2GB
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
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
2,653 Expert 2GB
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
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
2,653 Expert 2GB
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

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

Similar topics

1
by: Dan | last post by:
Could someone please help me with auto importing a series of data files into an Access table. I tried to follow code given below in a previous messagebut i'm getting error messages. Here's my...
15
by: daniroy | last post by:
Hello everybody, your help will be very very welcome on a very classic question... I have some Excell Macro background, a little bit of VBA knowledge. I import daily from Internet series of...
4
by: Bob | last post by:
I'm running Access 97 and have a sub-form within a main form. The subform allows data entry by the user. Now, I would also like to enter a row from a macro, but when I try, the entry always goes...
8
by: Nick M | last post by:
Hello All, Excellent info here Thanks! I am very new to using access in general and I am on a learning curve. I'm trying to import an excel workbook (with worksheets) into an access db via a...
1
by: ghadley_00 | last post by:
Hi, I have a MS access database table for which I regularly need to import fixed width text data. At present I have to to cut and paste the text data from its source to a text file, save the...
10
by: Niklas | last post by:
Hi Before I start coding I need to be sure that nobody else has not done it yet and that I can use it. I need an import utility which import data from Excel to a database or some object in...
3
by: ninrulz | last post by:
I will try to explain my situation. I know that it is hard to offers solutions without fully understanding what people would like to achieve. I receive 2 csv files every month. The csv files...
1
by: lorirobn | last post by:
Hi, I have been manually importing a text file on a weekly basis to an Access table. The data on one field is about to change (happens to be the first field). It was numeric, and is defined as...
6
by: provor | last post by:
Hello, I have the following code that I am using when a user presses a button to import an excel file into a table. The code is hard coded to point to the correct table. This works great for this...
0
by: Hystou | last post by:
There are some requirements for setting up RAID: 1. The motherboard and BIOS support RAID configuration. 2. The motherboard has 2 or more available SATA protocol SSD/HDD slots (including MSATA, M.2...
0
marktang
by: marktang | last post by:
ONU (Optical Network Unit) is one of the key components for providing high-speed Internet services. Its primary function is to act as an endpoint device located at the user's premises. However,...
0
by: Hystou | last post by:
Most computers default to English, but sometimes we require a different language, especially when relocating. Forgot to request a specific language before your computer shipped? No problem! You can...
0
jinu1996
by: jinu1996 | last post by:
In today's digital age, having a compelling online presence is paramount for businesses aiming to thrive in a competitive landscape. At the heart of this digital strategy lies an intricately woven...
1
by: Hystou | last post by:
Overview: Windows 11 and 10 have less user interface control over operating system update behaviour than previous versions of Windows. In Windows 11 and 10, there is no way to turn off the Windows...
0
tracyyun
by: tracyyun | last post by:
Dear forum friends, With the development of smart home technology, a variety of wireless communication protocols have appeared on the market, such as Zigbee, Z-Wave, Wi-Fi, Bluetooth, etc. Each...
0
isladogs
by: isladogs | last post by:
The next Access Europe User Group meeting will be on Wednesday 1 May 2024 starting at 18:00 UK time (6PM UTC+1) and finishing by 19:30 (7.30PM). In this session, we are pleased to welcome a new...
0
by: conductexam | last post by:
I have .net C# application in which I am extracting data from word file and save it in database particularly. To store word all data as it is I am converting the whole word file firstly in HTML and...
0
by: TSSRALBI | last post by:
Hello I'm a network technician in training and I need your help. I am currently learning how to create and manage the different types of VPNs and I have a question about LAN-to-LAN VPNs. The...

By using Bytes.com and it's services, you agree to our Privacy Policy and Terms of Use.

To disable or enable advertisements and analytics tracking please visit the manage ads & tracking page.