Hi,
I am attempting to create a word document from VBA code in Access. I am having a problem with Normal.doc when running my code. If I delete normal.dot my code works fine and the document is created ok the first time I run it. Every time after, I usually get a error stating "Normal.dot caused a serious error last time it was opened, do you want to continue opening it?" Other times, it will simply open word (with no document open). One other thing I've noticed is that sometimes when I try to close the document it will ask me if I want to save changes to normal.dot.
This is very frustrating considering I got the code straight from a book about Access.
Here is the code:
Dim objWord As Word.Application
Dim objTable As Word.Table
On Error Resume Next
'Use a running word instance if possible
Set objWord = GetObject(, Word.Application)
'Otherwise use a new instance
If objWord Is Nothing Then
Set objWord = New Word.Application
'If true, Word is not installed.
If objWord Is Nothing Then
MsgBox "Word is not installed on your system"
End If
End If
objWord.Documents.Add
objWord.Activate
objWord.Visible = True
objWord.Selection.TypeText Text:="203 Rose Avenue"
Set objWord = Nothing
Exit Sub
I have tried deleting normal.dot and also making it read only. I have also tried re-installing office. No luck there.
I have tried the code on two other machines. On one machine (Win XP Pro, Office XP Pro) it runs fine, but on another (Win XP Pro, Office XP Pro) it has the same troubles as the machine I am currently developing on (Win XP Home, Office XP Pro).
Someone please help!
I am attempting to create a word document from VBA code in Access. I am having a problem with Normal.doc when running my code. If I delete normal.dot my code works fine and the document is created ok the first time I run it. Every time after, I usually get a error stating "Normal.dot caused a serious error last time it was opened, do you want to continue opening it?" Other times, it will simply open word (with no document open). One other thing I've noticed is that sometimes when I try to close the document it will ask me if I want to save changes to normal.dot.
This is very frustrating considering I got the code straight from a book about Access.
Here is the code:
Dim objWord As Word.Application
Dim objTable As Word.Table
On Error Resume Next
'Use a running word instance if possible
Set objWord = GetObject(, Word.Application)
'Otherwise use a new instance
If objWord Is Nothing Then
Set objWord = New Word.Application
'If true, Word is not installed.
If objWord Is Nothing Then
MsgBox "Word is not installed on your system"
End If
End If
objWord.Documents.Add
objWord.Activate
objWord.Visible = True
objWord.Selection.TypeText Text:="203 Rose Avenue"
Set objWord = Nothing
Exit Sub
I have tried deleting normal.dot and also making it read only. I have also tried re-installing office. No luck there.
I have tried the code on two other machines. On one machine (Win XP Pro, Office XP Pro) it runs fine, but on another (Win XP Pro, Office XP Pro) it has the same troubles as the machine I am currently developing on (Win XP Home, Office XP Pro).
Someone please help!
Last edited: