Setting word objext details from Access

F

Frank H

Can somebody assist.
I am launching word from Access by creating a Word object, using bookmarks
in a 'template' document to fill some details from an Access mdb table then
setting the word object application to visible. This works fine. The only
problem I have is that the document opens with the cursor at the beginning of
the text, and I want it to simply go to the end of the text. Can somebody
advise what the correct statement is (eg objWordDoc. ???)

I have not tried this before, so would appreciate any advice to improve on
this method if there is one.

Would also appreciate link to any info, where this sort of stuff is
explained SIMPLY

TIA Frank H
 
P

Peter Hibbs

Frank,

Try this :-

objWordDoc.Selection.EndKey Unit:=wdStory

This command simulates pressing CONTROL + END on the keyboard which
moves the cursor to the end of the document. Did you know that you can
use Word's Macros to see what code to use. For example, if you open
your Word document and place the cursor at the beginning of the text.
Start a new Macro in 'record' mode, press CONTROL + END and then stop
the Macro. If you then look at the code for the Macro it should show
something like :-

Sub Macro1()
'
' Macro1 Macro
' Macro recorded 02/11/2008 by P D Hibbs
'
Selection.EndKey Unit:=wdStory
End Sub

To use this function from Access you just prefix it with your object
definition as I have shown above.

Regarding you second question, I did a quick Google but I could not
find any sort of easy-to-use Word tutorial on VBA programming. I use a
book called 'Word 2000 Developer's Handbook' by Guy Hart-Davis which
is about three inches thick and has everything you want to know about
Word VBA. Alternatively you could use the MS Word newsgroups who will
probably be able to tell you how to do any code in Word which will be
pretty much the same in Access.

HTH

Peter Hibbs.
 
F

Frank H

Thanks for the reply Peter

This was indeed the method that I tried. I got an error code when I tried
it, & assumed I couldnt do it that way.

Error: 438 Object doesnt support this property or method

Any ideas ?

Thanks Frank H
 
P

Pete D.

Did you add the reference to word in your code window? Microsoft XX.XX
Object library. Replace X with correct version numbers.
 
F

Frank H

Peter

I added ref to Microsoft Word 10.0 object library
Same result

TIA Frank H
 
F

Frank H

Got it Peter, correct format is objWordDoc.Application.selection...etc

Thanks again for your help
 
P

Peter Hibbs

Frank,

That is odd. I tested my code before I posted it and it worked OK. I
tried your version and that worked OK as well. I tried my version
using Early and Late Binding which makes no difference and I tried it
with A2000 and A2003 and it still works OK. There seems to be
something different in your set up and mine, I wonder what. Anyway, if
it works that is the main thing.

Peter Hibbs.
 

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