Run Word vba in Access module

G

greeknl

Hi,

I am new here, I have learned a lot from this forum and my thanks to all
repliers with thaeir great suggestions.

But I have a question, using office 2003:
I am writing a vba module in Access to create a word document with values
from a the database. Everything ok there. I now want to add in the word
document a checkbox and a field counting pages.
I have managed to create a line using:

Dim oApp As Object
Set oApp = CreateObject("Word.Application")
oApp.Visible = True
With oApp
.Selection.InlineShapes.AddHorizontalLineStandard

and I was also able to change the properties of the line.
As said I want to create a a checkbox and a field.

when using these commands, which I used in word vba and check again using the
macro recording tool in word I get errors what am I doing wrong?
.Selection.FormFields.Add Range:=Selection.Range, Type:=wdFieldFormCheckBox
.Selection.Fields.Add Range:=Selection.Range, Type:=wdFieldNumPages

I do not want to use records in Access of do this via a Word template.

Thank you
 
J

John Nurick

You don't say what error you're getting, but I'll guess that Access VBA
is not recognising the Word constants wdFieldFormCheckbox and
wdFieldNumPages.

You need to either
-go to Tools|References in the VB Editor and add a reference to
Microsoft Word 11.0 Object Library,
or
-replace the constants with their literal values (e.g.
wdFieldFormCheckBox = 71).

I'd do the first; this means you'll also be able to declare
Dim oApp As Word.Application
(this is called 'early binding') and get the Intellisense features of
the VBE working on the Word objects as well as the Access ones.
 
G

greeknl

THANKS

I already had done step 1.
I replaced the wd... statement with the value 71 and voila there it was.
I have been trying to find the list with those constants. Can you help me on
this? Is there a list of all wd.... values available?

I suppose this also works with the numpages field I want to put in the
document?

You have been a real help.
Also this forum is one of the best I found on the net.

Thanks again
 
D

Douglas J. Steele

Best way I know of is to go into the VB Editor in Word, and determine the
values in the Immediate window.

You can also go through the Object Browser while in Word (or from Access if
you have a reference set to Word).
 

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