PLEASE HELP!!: Type Mismatch error

  • Thread starter Thread starter sam
  • Start date Start date
S

sam

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 said:
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


Answered in another newsgroup where you posted the same question.

Note: rather than posting the same question independently to multiple
newsgroups ("multiposting"), it's better to list multiple newsgroups (where
appropriate) on the "To" line of your post ("crossposting"). The web
interface doesn't make it obvious that you can do this, but there is an
option for it.
 
This worked out great! Thanks a lot Dik.

Dirk Goldgar said:
Answered in another newsgroup where you posted the same question.

Note: rather than posting the same question independently to multiple
newsgroups ("multiposting"), it's better to list multiple newsgroups (where
appropriate) on the "To" line of your post ("crossposting"). The web
interface doesn't make it obvious that you can do this, but there is an
option for it.

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

(please reply to the newsgroup)
 
Back
Top