Hello all,
I am trying to open an existing word document in access that works fine, but then if the word document does not exist i want to create a word document with a name assigned in a field called instructiosnID. The problem is that when the files does not exist and try to create a new one does not create it what it does is only opens words with no document at all, then if am trying to save with the name in Instructions ID it gives me an error saying that there is no active document. All i want is when open word also creates the blank word document with a name "1234.doc". Thank you very much in advance
Here is the code:
Private Sub cmdowd_Click() 'Open Word Document
On Error GoTo handlerror
Dim objWord As Object, objWord2 As Object
Dim ffile As String
Set objWord = CreateObject("Word.Application")
objWord.Visible = True
ffile = Application.CurrentProject.Path & "\" & Me.InstructionID & ".doc"
objWord.documents.Open ffile
objWord.Visible = True
exiterror:
Exit Sub
handlerror:
If Err.Number = 5174 Then 'if word document does not exist, create one with the name in InstructionsID
Set objWord2 = New Word.Application
objWord2.Visible = True
objWord2.ActiveDocument.SaveAs Application.CurrentProject.Path & "\" & Me.InstructionID & ".doc"
Else
MsgBox Err.Description
End If
Resume exiterror
End Sub
I am trying to open an existing word document in access that works fine, but then if the word document does not exist i want to create a word document with a name assigned in a field called instructiosnID. The problem is that when the files does not exist and try to create a new one does not create it what it does is only opens words with no document at all, then if am trying to save with the name in Instructions ID it gives me an error saying that there is no active document. All i want is when open word also creates the blank word document with a name "1234.doc". Thank you very much in advance
Here is the code:
Private Sub cmdowd_Click() 'Open Word Document
On Error GoTo handlerror
Dim objWord As Object, objWord2 As Object
Dim ffile As String
Set objWord = CreateObject("Word.Application")
objWord.Visible = True
ffile = Application.CurrentProject.Path & "\" & Me.InstructionID & ".doc"
objWord.documents.Open ffile
objWord.Visible = True
exiterror:
Exit Sub
handlerror:
If Err.Number = 5174 Then 'if word document does not exist, create one with the name in InstructionsID
Set objWord2 = New Word.Application
objWord2.Visible = True
objWord2.ActiveDocument.SaveAs Application.CurrentProject.Path & "\" & Me.InstructionID & ".doc"
Else
MsgBox Err.Description
End If
Resume exiterror
End Sub