473,406 Members | 2,467 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,406 software developers and data experts.

Inserting value from MS Word into MS Access

If there are any enlightend souls out there that can help me, I would
greatly appreciate it. I would like to use a macro to take a value and
add it to an access database.

I am having a problem with the very first line of code,
Dim myDatabase as Database, the system does not recognize the Database
object.

PLEASE if there is anyone out there that has a piece of code that
sends info from a word file into a access database... send it to me. I
will Love you forever.
Nov 13 '05 #1
8 1637
Evan wrote:
If there are any enlightend souls out there that can help me, I would
greatly appreciate it. I would like to use a macro to take a value and
add it to an access database.

I am having a problem with the very first line of code,
Dim myDatabase as Database, the system does not recognize the Database
object.


Add a reference to DAO or use an Object variable and late bind it (set
db=CreateObject("DAO.Database"), although the first way will give you
intellisense.

--

\\\\\\
\\ \\ Windows is searching
\ \ For your sig.
\ \ Please Wait.
\__\

Nov 13 '05 #2
mmm, I am sorry - I am really new at this... I have added the ADO
reference, and I want to execute this SQL - "insert into documents
(title) values ('testTitle')"

How do I write the actual code, I had it before but then I deleted the
wrong file... now I am back at square one
Nov 13 '05 #3
Evan wrote:
mmm, I am sorry - I am really new at this... I have added the ADO
reference, and I want to execute this SQL - "insert into documents
(title) values ('testTitle')"

How do I write the actual code, I had it before but then I deleted the
wrong file... now I am back at square one


I've not done much in thew way of ADO, at least with Access so I don't
know the connection string to use but it's something like:

Dim cn As New ADODB.Connection
cn.open "connection string here"
cn.Execute "insert..."
cn.close
set cn=nothing

--

\\\\\\
\\ \\ Windows is searching
\ \ For your sig.
\ \ Please Wait.
\__\

Nov 13 '05 #4

"Trevor Best" <nospam@localhost> wrote in message
news:41***********************@auth.uk.news.easyne t.net...
I've not done much in thew way of ADO, at least with Access so I don't
know the connection string to use but it's something like:

Dim cn As New ADODB.Connection
cn.open "connection string here"
cn.Execute "insert..."
cn.close
set cn=nothing

With ADO in A2000+,

Dim cnxn As ADODB.Connection
Set cnxn = CurrentProject.Connection
cnxn.Execute "INSERT ..."

This works in MDB, not just ADP. I have seen no benefit in closing this
connection (quite the contrary) or setting it to nothing. There is a
benefit in closing and setting recordsets to nothing, of course.

Darryl Kerkeslager
Nov 13 '05 #5
Darryl Kerkeslager wrote:
With ADO in A2000+,

Dim cnxn As ADODB.Connection
Set cnxn = CurrentProject.Connection
cnxn.Execute "INSERT ..."

This works in MDB, not just ADP. I have seen no benefit in closing this
connection (quite the contrary) or setting it to nothing. There is a
benefit in closing and setting recordsets to nothing, of course.


The OP wants to do this from MS Word, so CurrentProject.Connection won't
work :-( It would also be an idea to close it afterwards from there.

BTW I would close the connection in Access if it were a local variable,
I know it just points to an already established connection but it's
still a variable and uses resources, which I wouldn't trust Access VBA
alone to clean it up and release. Too often with all the apps I run, the
system's using 256MB RAM after I close all apps, when I boot up it's
using 128MB so something somewhere is using 128MB RAM and not releasing
it, I wouldn't try to compound that by not cleaning up my variables,
it's bad enough in Windows without me being sloppy and adding to the
problem.

In general, like when I use DAO I have a global Database variable that I
set to the currentdb. This remains available for instant use all the
time from anywhere without having to Set/Open, etc before use. Then I
clean it up before exiting the app.

--

\\\\\\
\\ \\ Windows is searching
\ \ For your sig.
\ \ Please Wait.
\__\

Nov 13 '05 #6
Darryl Kerkeslager wrote:

Dim cnxn As ADODB.Connection
Set cnxn = CurrentProject.Connection
cnxn.Execute "INSERT ..."

This works in MDB, not just ADP. I have seen no benefit in closing this
connection (quite the contrary) or setting it to nothing. There is a
benefit in closing and setting recordsets to nothing, of course.
"Trevor Best" <nospam@localhost> wrote:

BTW I would close the connection in Access if it were a local variable,
I know it just points to an already established connection but it's
still a variable and uses resources, which I wouldn't trust Access VBA
alone to clean it up and release.
The reason I say not to close it is perhaps a quirk of Access, but enough of
a headache for me that I said, "never again": setting the connection to
nothing inside a nested call set the outer connection to nothing as well.
Now, perhaps it was my mistake, and I had used a public cnxn variable, as I
do now - I don't remember - but having to worry about whether my function is
being called by anotehr function using CurrentProject.Connection was too
much effort.

Public cnxn As ADODB.Connection

Private Sub Form_Open()
Set cnxn = CurrentProject.Connection
If CalledFunction() then
cnxn.Execute "INSERT ..."
endif
End Sub

Private Function CalledFunction() As Boolean
Set cnxn = CurrentProject.Connection
cnxn.Execute "DELETE * FROM ..."
Set cnxn = Nothing <-- closes open
connection, creating error in Form_Open
End Function

Then I clean it up before exiting the app.


I could do this, I suppose, but my feeling has been that if it is only one
connection object, no big deal. As I said, I do Set all recordsets =
Nothing when I use them.
Darryl Kerkeslager

Nov 13 '05 #7
Darryl Kerkeslager wrote:
Then I clean it up before exiting the app.

I could do this, I suppose, but my feeling has been that if it is only one
connection object, no big deal. As I said, I do Set all recordsets =
Nothing when I use them.


I do sometimes wonder I bother with the closing and setting to nothing
of a global db variable at the end. I have such db variable opened with
OpenDatabase() to a SQL Server, when I close my app, I close this
connection and set it to nothing. Then even when I close the database
(the actual database window so no mdb is open in Access) my connection
is still there.

As a further test, if I first log onto SQL server as plebe, then close
the mdb (closing ans setting to nothing my db variable to the sql
server) and reopen and log on as "sa", I can't do sa type things. This
could cause a severe security breach the other way around, i.e. plebe
could have sa privileges.

--

\\\\\\
\\ \\ Windows is searching
\ \ For your sig.
\ \ Please Wait.
\__\

Nov 13 '05 #8

"Trevor Best" <nospam@localhost> wrote:

As a further test, if I first log onto SQL server as plebe, then close
the mdb (closing ans setting to nothing my db variable to the sql
server) and reopen and log on as "sa", I can't do sa type things. This
could cause a severe security breach the other way around, i.e. plebe
could have sa privileges.


I'm not very familiar with SQL Server, but this sounds kinda bad...

Nov 13 '05 #9

This thread has been closed and replies have been disabled. Please start a new discussion.

Similar topics

4
by: Tom Dauria | last post by:
What I am trying to do is write a resume into a word document from information in an Access database. I have been using bookmarks and inserting table results into the document and so far it's...
3
by: sms1 | last post by:
My Participants table in Access 2002 contains about 1500 records. The Notes field is OLE. I want to use Insert Object to insert MS Word into the Notes field. It is easily done using: Insert...
0
by: ajk | last post by:
Hi, All: I know how to insert files into a Word doc using C#. However, the program I've written to do this runs much too slowly. The "myObj".Application.Selection.InsertFile method executes at a...
1
by: ajk | last post by:
. Hi, All: I know how to insert files into a Word doc using C#. However, the program I've written to do this runs much too slowly. The "myObj".Application.Selection.InsertFile method executes...
6
by: Flurry | last post by:
Hello I have a simple problem but I think the solution might be tricky... I have a word document on the server which people can download. However, what I would like is to use asp.net to insert...
2
by: santuvssantu | last post by:
Hi Friends, I have tried inserting an excel file to a word document.But the following code is inserting the junk information. So can you please help me out? Dim m_WordApp As New...
1
by: Mike Fellows | last post by:
I have some images stored locally that i retrieve and insert into a word document that is programatically created im using the following code If File.Exists("C:\Pic2.jpg") Then...
2
by: hakkatil | last post by:
Hi to all, I have a page that inserts excel sheet to access database. I am using asp. What I want to do is to check the inserting record if it is in the database. Basicly checking the dublicate...
5
by: rando1000 | last post by:
Okay, here's my situation. I need to loop through a file, inserting records based on a number field (in order) and if the character in a certain field = "##", I need to insert a blank record. ...
0
by: Charles Arthur | last post by:
How do i turn on java script on a villaon, callus and itel keypad mobile phone
0
BarryA
by: BarryA | last post by:
What are the essential steps and strategies outlined in the Data Structures and Algorithms (DSA) roadmap for aspiring data scientists? How can individuals effectively utilize this roadmap to progress...
1
by: nemocccc | last post by:
hello, everyone, I want to develop a software for my android phone for daily needs, any suggestions?
1
by: Sonnysonu | last post by:
This is the data of csv file 1 2 3 1 2 3 1 2 3 1 2 3 2 3 2 3 3 the lengths should be different i have to store the data by column-wise with in the specific length. suppose the i have to...
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
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...
0
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
agi2029
by: agi2029 | last post by:
Let's talk about the concept of autonomous AI software engineers and no-code agents. These AIs are designed to manage the entire lifecycle of a software development project—planning, coding, testing,...
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...

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.