I have a word document that I can successfuly open from Access code. I can also fill out some bookmarks on this document using fields from the calling form in Access.
My problem is adding additional information to this document that has to come from a query. I have written the query, and it works perfectly. I have attempted to fit the SQL into the code, but to no avail. This is the code that I'm working with - some of it is not mine and I don't know what it does.
Dim Result As Long
Dim WordApp As Object
Dim ReadOnly As Integer
Dim objword As Word.Application
Dim objDoc As Word.Document
Dim dbMidbase As Database
Dim rsMidbase As Recordset
Dim sSql As String
Set objword = New Word.Application
objword.Visible = True
Set objDoc = objword.Documents.Open("document", , 1)
objword.Activate
objDoc.Bookmarks("Company"
.Range.text = CompanyCombo
objDoc.Bookmarks("Person"
.Range.text = PersonName
objDoc.Bookmarks("Date"
.Range.text = TDate
sSql = "SELECT Documents.DRegistrationNumber, Jobs.[Job No], Jobs.Department, Jobs.[Job Name] FROM Documents INNER JOIN Jobs ON Documents.DOurJob = Jobs.[Job No]WHERE (((Documents.DRegistrationNumber)=[Forms]![Transmissions]![TDRegCombo]))"
Set dbMidbase = OpenDatabase("\\midbdata97.mdb"
'note this is my data file, not my application file
Set rsMidbase = dbMidbase.OpenRecordset(sSql)
objDoc.Bookmarks("Project"
.Range.text = rsMidbase.Fields("Job Name"
'this part doesn't work
Set objDoc = Nothing
Set objword = Nothing
Set dbMidbase = Nothing
Set rsMidbase = Nothing
Any suggestions? Is there a better way to do this?
Regards and thanks in advance.
My problem is adding additional information to this document that has to come from a query. I have written the query, and it works perfectly. I have attempted to fit the SQL into the code, but to no avail. This is the code that I'm working with - some of it is not mine and I don't know what it does.
Dim Result As Long
Dim WordApp As Object
Dim ReadOnly As Integer
Dim objword As Word.Application
Dim objDoc As Word.Document
Dim dbMidbase As Database
Dim rsMidbase As Recordset
Dim sSql As String
Set objword = New Word.Application
objword.Visible = True
Set objDoc = objword.Documents.Open("document", , 1)
objword.Activate
objDoc.Bookmarks("Company"
objDoc.Bookmarks("Person"
objDoc.Bookmarks("Date"
sSql = "SELECT Documents.DRegistrationNumber, Jobs.[Job No], Jobs.Department, Jobs.[Job Name] FROM Documents INNER JOIN Jobs ON Documents.DOurJob = Jobs.[Job No]WHERE (((Documents.DRegistrationNumber)=[Forms]![Transmissions]![TDRegCombo]))"
Set dbMidbase = OpenDatabase("\\midbdata97.mdb"
Set rsMidbase = dbMidbase.OpenRecordset(sSql)
objDoc.Bookmarks("Project"
Set objDoc = Nothing
Set objword = Nothing
Set dbMidbase = Nothing
Set rsMidbase = Nothing
Any suggestions? Is there a better way to do this?
Regards and thanks in advance.