PLEASE HELP:Type Mismatch Error: Set doc=wdApp.Documents.Open(fDia

Discussion in 'Microsoft Access Form Coding' started by Sam, Sep 4, 2009.

  1. Sam

    Sam Guest

    Hi All,

    I am trying to create a button on access form that would export some of the
    fields to a word template. I think I have it right but I am getting a type
    mismatch error on this line:

    Set doc = wdApp.Documents.Open(fDialog)

    what might be the reason? Here is the whole code:

    Dim wdApp As Object
    Dim doc As Object
    On Error Resume Next
    Set wdApp = GetObject("C:\My Documents\Address.dotx", "Word.Application")

    If Err.Number <> 0 Then 'Word isn't already running
    Set wdApp = CreateObject("Word.Application")
    End If
    On Error GoTo 0

    Dim FName As String

    fDialog = Application.FileDialog(msoFileDialogFilePicker).Show

    On Error Resume Next
    Set doc = wdApp.Documents.Open(fDialog)

    wdApp.ActiveDocument.Variables("Address").Value = Me.Address.Value
    wdApp.ActiveDocument.Variables("City").Value = Me.City.Value

    wdApp.ActiveDocument.Fields.Update

    FName = "C:\My Documents\" & "Address" & ".doc"

    wdApp.ActiveDocument.SaveAs FileName:=FName

    wdApp.Visible = True

    Set doc = Nothing
    Set wdApp = Nothing
    wApp.Quit

    End Sub

    Please help!

    Thanks in advance
     
    Sam, Sep 4, 2009
    #1
    1. Advertisements

  2. Sam

    Dirk Goldgar Guest

    "Sam" <> wrote in message
    news:...
    > Hi All,
    >
    > I am trying to create a button on access form that would export some of
    > the
    > fields to a word template. I think I have it right but I am getting a type
    > mismatch error on this line:
    >
    > Set doc = wdApp.Documents.Open(fDialog)
    >
    > what might be the reason? Here is the whole code:
    >
    > Dim wdApp As Object
    > Dim doc As Object
    > On Error Resume Next
    > Set wdApp = GetObject("C:\My Documents\Address.dotx", "Word.Application")
    >
    > If Err.Number <> 0 Then 'Word isn't already running
    > Set wdApp = CreateObject("Word.Application")
    > End If
    > On Error GoTo 0
    >
    > Dim FName As String
    >
    > fDialog = Application.FileDialog(msoFileDialogFilePicker).Show
    >
    > On Error Resume Next
    > Set doc = wdApp.Documents.Open(fDialog)
    >
    > wdApp.ActiveDocument.Variables("Address").Value = Me.Address.Value
    > wdApp.ActiveDocument.Variables("City").Value = Me.City.Value
    >
    > wdApp.ActiveDocument.Fields.Update
    >
    > FName = "C:\My Documents\" & "Address" & ".doc"
    >
    > wdApp.ActiveDocument.SaveAs FileName:=FName
    >
    > wdApp.Visible = True
    >
    > Set doc = Nothing
    > Set wdApp = Nothing
    > wApp.Quit
    >
    > End Sub



    The Show method of the FileDialog object returns a Long value indicating
    whether the user pressed the action button (-1) or the cancel button (0).
    It doesn't return the name of the file selected as a string, which seems to
    be what your code is expecting. Instead, you have to get the selected
    filename from the dialog's SelectedItems collection. See the example in the
    online help.

    --
    Dirk Goldgar, MS Access MVP
    Access tips: www.datagnostics.com/tips.html

    (please reply to the newsgroup)
     
    Dirk Goldgar, Sep 4, 2009
    #2
    1. Advertisements

Want to reply to this thread or ask your own question?

It takes just 2 minutes to sign up (and it's free!). Just click the sign up button to choose a username and then you can ask your own questions on the forum.
Similar Threads
  1. Krisse

    Type mismatch error in set statement

    Krisse, Jul 18, 2003, in forum: Microsoft Access Form Coding
    Replies:
    1
    Views:
    221
    Krisse
    Jul 19, 2003
  2. Chris

    Type mismatch error - Please Help

    Chris, Nov 17, 2003, in forum: Microsoft Access Form Coding
    Replies:
    2
    Views:
    132
    Treebeard
    Nov 17, 2003
  3. shmoussa

    Error 13 Type Mismatch again...HELP PLEASE

    shmoussa, Jun 20, 2007, in forum: Microsoft Access Form Coding
    Replies:
    1
    Views:
    112
    Stefan Hoffmann
    Jun 20, 2007
  4. Al

    Please help with type mismatch error.

    Al, Mar 10, 2009, in forum: Microsoft Access Form Coding
    Replies:
    4
    Views:
    131
  5. mané_uk

    Date type Variable - Type Mismatch

    mané_uk, Jul 8, 2009, in forum: Microsoft Access Form Coding
    Replies:
    5
    Views:
    525
    Douglas J. Steele
    Jul 8, 2009
Loading...

Share This Page