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?

You'll need to choose a username for the site, which only take a couple of moments (here). After that, you can post your question and our members will help you out.
Similar Threads
  1. Krisse

    Type mismatch error in set statement

    Krisse, Jul 18, 2003, in forum: Microsoft Access Form Coding
    Replies:
    1
    Views:
    413
    Krisse
    Jul 19, 2003
  2. Gina Whipp

    Error message '13 Type Mismatch' HELP!

    Gina Whipp, Oct 1, 2003, in forum: Microsoft Access Form Coding
    Replies:
    7
    Views:
    356
    Fred Boer
    Oct 1, 2003
  3. Chris

    Type mismatch error - Please Help

    Chris, Nov 17, 2003, in forum: Microsoft Access Form Coding
    Replies:
    2
    Views:
    267
    Treebeard
    Nov 17, 2003
  4. Error 13 Type Mismatch HELP!!!

    , Jul 12, 2006, in forum: Microsoft Access Form Coding
    Replies:
    1
    Views:
    280
    RoyVidar
    Jul 12, 2006
  5. shmoussa

    Error 13 Type Mismatch again...HELP PLEASE

    shmoussa, Jun 20, 2007, in forum: Microsoft Access Form Coding
    Replies:
    1
    Views:
    219
    Stefan Hoffmann
    Jun 20, 2007
  6. Guest

    Form/Subform/Command Button to Open Form - Type Mismatch Error

    Guest, Jul 12, 2007, in forum: Microsoft Access Form Coding
    Replies:
    2
    Views:
    1,077
    Guest
    Jul 12, 2007
  7. Al

    Please help with type mismatch error.

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

    Date type Variable - Type Mismatch

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