PC Review


Reply
Thread Tools Rate Thread

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

 
 
Sam
Guest
Posts: n/a
 
      4th Sep 2009
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

 
Reply With Quote
 
 
 
 
Dirk Goldgar
Guest
Posts: n/a
 
      4th Sep 2009
"Sam" <(E-Mail Removed)> wrote in message
news:(E-Mail Removed)...
> 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)

 
Reply With Quote
 
 
 
Reply

Thread Tools
Rate This Thread
Rate This Thread:

Posting Rules
You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts

BB code is On
Smilies are On
[IMG] code is On
HTML code is Off
Trackbacks are On
Pingbacks are On
Refbacks are Off


Similar Threads
Thread Thread Starter Forum Replies Last Post
cant install vista im going crazy please help please please please =?Utf-8?B?TWFuTmVlZEhlbHA=?= Windows Vista Installation 2 31st Jul 2006 02:55 PM
cant install vista im going crazy please help please please please =?Utf-8?B?TWFuTmVlZEhlbHA=?= Windows Vista Installation 2 30th Jul 2006 09:31 PM
XP SP2 Please wait ... please wait ... please wait ... please wait ... PK Windows XP General 0 27th Aug 2004 12:02 AM
Help! Anyone! Please Please Please Please Please Please =?Utf-8?B?UmFuZHk=?= Microsoft Access Macros 2 17th May 2004 07:16 PM
Type mismatch error (different than previous type mismatch?) Roberta Microsoft Access VBA Modules 3 9th Jan 2004 07:26 PM


Features
 

Advertising
 

Newsgroups
 


All times are GMT +1. The time now is 12:25 AM.