Re: Open or Create word document from within Access



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 :-)
>
>
.



Relevant Pages

  • Re: Open or Create word document from within Access
    ... Public Function OpenFile(strFileName As String) ... 'use the Open method for an existing file ... Set doc = wrd.Documents.Open ... This reply is posted in the Newsgroup; please post any follow question or reply ...
    (microsoft.public.office.developer.automation)
  • "Shell"ing to Adobe update question
    ... Dim strFilePath As String ... Dim strAcrobatPath As String ... 'set the file path for the pdf file ...
    (comp.databases.ms-access)
  • RE: Relative Value Macros
    ... names already put in a column in one workbook, ... Dim strFilePath As String ... Public Function FileNameFromPath(ByVal strPath As String) As String ...
    (microsoft.public.excel.programming)
  • Re: Common Dialog Box
    ... > Dim strFilePath As String ... > strPath will return the path to the selected file for you to save ... Secret Character, have a look at these web pages: ...
    (microsoft.public.access.forms)
  • Re: What is wrong with this sub-routine?
    ... > ' Basic macro for finding files. ... > Dim strFilePath As String ... > 'Find and open files associated with selected unit. ...
    (microsoft.public.word.vba.general)