R
ryguy7272
I have been experimenting with a new technique (new for me) all day today. I
was trying to modify some code to send data from a From to a Word.doc with
several Bookmarks. Below is my code:
Option Compare Database
Option Compare Database
Sub PatientForm()
Dim appWord As Word.Application
Dim doc As Word.Document
Dim objWord As Object
On Error Resume Next
err.Clear
Set appWord = GetObject(, "Word.Application")
Set objWord = CreateObject("Word.Application")
If err.Number <> 0 Then
objWord.Documents.Open CurrentProject.Path & "\test.doc"
objWord.Visible = True
End If
Set doc = appWord.Documents.Open("C:\PatientForm.doc", , True)
With doc
..FormFields("LastName").Result = Forms!SearchForm!frmsubClients.Form.LastName
..FormFields("FirstName").Result =
Forms!SearchForm!frmsubClients.Form.FirstName
..FormFields("ConsultDate").Result =
Forms!SearchForm!frmsubClients.Form.ConsultDate
..Visible = True
..Activate
End With
Set doc = Nothing
Set appWord = Nothing
Exit Sub
errHandler:
MsgBox err.Number & ": " & err.Description
End Sub
It works, I am just trying to figure out a way to open the Word.doc and
‘push’ the data from the Form to the Word.doc. As I understand it, this code
will open the Word.doc:
Dim objWord As Object
Set objWord = CreateObject("Word.Application")
'Assumes document in same folder as MDB.
objWord.Documents.Open CurrentProject.Path & "\test.doc"
objWord.Visible = True
This works fine, and I love the fact that the MDB is in the same location as
the Word.doc. I am now trying to change the below line of code to make the
location of the Word.doc relative (and not absolute):
Set doc = appWord.Documents.Open("C:\PatientForm.doc", , True)
How can I modify my code to tell Access that the Word.doc and the MDB are
both in the same directory, without specifically mapping to that directory?
I am trying to prepare this for people who know nothing about VBA.
Regards,
Ryan---
was trying to modify some code to send data from a From to a Word.doc with
several Bookmarks. Below is my code:
Option Compare Database
Option Compare Database
Sub PatientForm()
Dim appWord As Word.Application
Dim doc As Word.Document
Dim objWord As Object
On Error Resume Next
err.Clear
Set appWord = GetObject(, "Word.Application")
Set objWord = CreateObject("Word.Application")
If err.Number <> 0 Then
objWord.Documents.Open CurrentProject.Path & "\test.doc"
objWord.Visible = True
End If
Set doc = appWord.Documents.Open("C:\PatientForm.doc", , True)
With doc
..FormFields("LastName").Result = Forms!SearchForm!frmsubClients.Form.LastName
..FormFields("FirstName").Result =
Forms!SearchForm!frmsubClients.Form.FirstName
..FormFields("ConsultDate").Result =
Forms!SearchForm!frmsubClients.Form.ConsultDate
..Visible = True
..Activate
End With
Set doc = Nothing
Set appWord = Nothing
Exit Sub
errHandler:
MsgBox err.Number & ": " & err.Description
End Sub
It works, I am just trying to figure out a way to open the Word.doc and
‘push’ the data from the Form to the Word.doc. As I understand it, this code
will open the Word.doc:
Dim objWord As Object
Set objWord = CreateObject("Word.Application")
'Assumes document in same folder as MDB.
objWord.Documents.Open CurrentProject.Path & "\test.doc"
objWord.Visible = True
This works fine, and I love the fact that the MDB is in the same location as
the Word.doc. I am now trying to change the below line of code to make the
location of the Word.doc relative (and not absolute):
Set doc = appWord.Documents.Open("C:\PatientForm.doc", , True)
How can I modify my code to tell Access that the Word.doc and the MDB are
both in the same directory, without specifically mapping to that directory?
I am trying to prepare this for people who know nothing about VBA.
Regards,
Ryan---