Home | Contact Us | FAQ | Search & Site Map | Link to Us
Sign In | Join | Other 45 Sites in Network
Home
DiscussionsAccessExcelInfoPathOutlookPowerPointPublisherWord
DirectoryUser Groups
Related Topics
Outlook ExpressInternet ExplorerWindowsMS Server ProductsMore Topics ...

MS Office Forum / Word / Programming / October 2007

Tip: Looking for answers? Try searching our database.

Getting Access records into Word 2003 VBA

Thread view: 
Enable EMail Alerts  Start New Thread
Thread rating: 
pacmedtran - 22 Oct 2007 01:00 GMT
Hi,
I'm having trouble opening a recordset in Word VBA to use Access data in a
macro.  Here is the code:

   Set objAccess = CreateObject("Access.Application")
   objAccess.DoCmd.SetWarnings False
   objAccess.OpenCurrentDatabase "PUTR.mdb"
   objAccess.DoCmd.OpenTable "ReadyList"

   Dim cnn1 As ADODB.Connection
   Set cnn1 = CurrentProject.Connection
   Dim varRecordSet1 As New ADODB.Recordset
   varRecordSet1.ActiveConnection = cnn1

The trouble comes at the last line, where I get a 3001 error that the
argument is the wrong type, out of range or in conflict.  That's as much help
as I get.

I do have the ActiveX Data Objects 2.1 object library referenced.  As far as
I can see, this ought to work, but I can't see what's wrong.  If anybody
could point out the obvious for me, I'd really appreciate it.
Tony Jollans - 22 Oct 2007 07:09 GMT
I'm surprised you get as far as the last line. What is CurrentProject in
your Word application?

You don't need to instantiate an Access application to use ADO to read a
database. Try just something like this ..

   Set cnn = New ADODB.Connection
   Set cmd = New ADODB.Command
   Set rst = New ADODB.Recordset

   cnn.Open "Provider=Microsoft.Jet.OLEDB.4.0;" & _
                   "Persist Security Info=False;"User ID=Admin;" & _
                   "Data Source=" & "PUTR.mdb"

   cmd.CommandText = "Select * from ReadyList;"
   cmd.ActiveConnection = cnn

   Set rst = cmd.Execute

Signature

Enjoy,
Tony

> Hi,
> I'm having trouble opening a recordset in Word VBA to use Access data in a
[quoted text clipped - 19 lines]
> I can see, this ought to work, but I can't see what's wrong.  If anybody
> could point out the obvious for me, I'd really appreciate it.
pacmedtran - 23 Oct 2007 18:49 GMT
That did the trick.  Thanks so much.

> I'm surprised you get as far as the last line. What is CurrentProject in
> your Word application?
[quoted text clipped - 38 lines]
> > I can see, this ought to work, but I can't see what's wrong.  If anybody
> > could point out the obvious for me, I'd really appreciate it.
 
Sign In
Join
My Latest Posts
My Monitored Threads
My Blog
My Photo Gallery
My Profile
My Homepage

Start New Thread
Enable EMail Alerts
Rate this Thread



©2008 Advenet LLC   Privacy Policy - Terms of Use
This website includes both content owned or controlled by Advenet as well as content owned or controlled by third parties.