Re: Open or Create word document from within Access
- From: "richardb" <richardb@xxxxxxxxxxxxxxxxxxxxxxxxx>
- Date: Wed, 13 Apr 2005 15:15:07 -0700
Thank you...
When I try this I get the error "User-defined type not defined" on the line:
Dim wrd As Word.Application
I do have the Office Object library attached as a reference.
"Cindy M -WordMVP-" wrote:
> Hi =?Utf-8?B?cmljaGFyZGI=?=,
>
> > I have attempted to write a routine in Access that will test if a Word file
> > exists; create if it does not exist; then open it for editing. I can't quite
> > get it. I get the error message "Invalid use of New keyword." (I attached the
> > Word 11 Object Library). I would appreciate if someone wouldn't mind
> > debugging this for me.
> >
> I'm inserting the commment 'HERE where I'd change things
>
> Public Function OpenFile(strFileName As String)
>
> Dim wrd As Word.Application
> Dim doc As Word.Document ''HERE
> Dim strFilePath As String
> Dim strDocument As String
>
> strFilePath = Trim(varLookup("Lookup", "tlkpStoredStrings", "VariableName =
> 'DocDir'")) 'varlookup is a replacement for DLookup.
> strDocument = strFilePath & "/" & strFileName & ".DOC"
> On Error GoTo Err_Exit
>
> 'HERE
> Set wrd = New Word.Application
>
> ' make sure both files exist
> If (Not bolFileExists(strDocument)) Then
> ' create new empty document
> 'HERE
> 'You first need to start up the Word application
> 'that's where you use the NEW keyword.
> 'To create a new document, use the .Add method
> 'of the Documents collection
> Set doc = wrd.Documents.Add
> doc.SaveAs FileName:=strDocument
> Else
> 'HERE
> 'use the Open method for an existing file
> Set doc = wrd.Documents.Open(strDocument)
> End If
>
> Cindy Meister
> INTER-Solutions, Switzerland
> http://homepage.swissonline.ch/cindymeister (last update Jun 8 2004)
> http://www.word.mvps.org
>
> This reply is posted in the Newsgroup; please post any follow question or reply
> in the newsgroup and not by e-mail :-)
>
>
.
- Follow-Ups:
- Re: Open or Create word document from within Access
- From: Cindy M -WordMVP-
- Re: Open or Create word document from within Access
- References:
- Open or Create word document from within Access
- From: richardb
- Re: Open or Create word document from within Access
- From: Cindy M -WordMVP-
- Open or Create word document from within Access
- Prev by Date: Re: Launching Word Mail Merge from Access VBA
- Next by Date: Re: add an appointment in a specific calendar in Outlook
- Previous by thread: Re: Open or Create word document from within Access
- Next by thread: Re: Open or Create word document from within Access
- Index(es):
Relevant Pages
|