Results 1 to 3 of 3
  1. #1
    2 Star Lounger
    Join Date
    Mar 2006
    Posts
    195
    Thanks
    0
    Thanked 0 Times in 0 Posts

    Word document (Access 2000)

    I have a function that open a word document to write notes in it.The functions works OK but only when a doc file name Notes is available.is it possible to create this word file in case it is not existing? In my function there is line called create object but somehow it does not work.

    My function is :
    Public Function MyNotes()
    Dim appW As Object
    On Error Resume Next
    Set appW = GetObject(, "Word.Application")
    Dim nErr As Integer
    nErr = Err
    On Error GoTo 0
    If nErr Then
    Set appW = CreateObject("Word.Application")
    End If
    appW.Visible = True
    appW.Documents.Open (" C:beNotes")
    End Function

  2. #2
    Plutonium Lounger
    Join Date
    Mar 2002
    Posts
    84,353
    Thanks
    0
    Thanked 29 Times in 29 Posts

    Re: Word document (Access 2000)

    Try

    Public Function MyNotes()
    Dim appW As Object
    Dim docW As Object
    Dim nErr As Integer
    Const strFile = "C:BeNotes.doc"
    On Error Resume Next
    Set appW = GetObject(, "Word.Application")
    nErr = Err
    On Error GoTo 0
    If nErr Then
    Set appW = CreateObject("Word.Application")
    End If
    ' Does document exist?
    If Dir(strFile) = "" Then
    ' If not, create it
    Set docW = appW.Documents.Add
    ' And save it
    docW.SaveAs strFile
    Else
    ' If it does exist, open it
    Set docW = appW.Documents.Open(strFile)
    End If
    appW.Visible = True
    Set docW = Nothing
    Set appW = Nothing
    End Function

  3. #3
    2 Star Lounger
    Join Date
    Mar 2006
    Posts
    195
    Thanks
    0
    Thanked 0 Times in 0 Posts

    Re: Word document (Access 2000)

    Thanks a lot, Hans !

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts
  •