Hi Guys
I am having a bit of trouble trying to get a Word Document to open from access and autofill with the information from a corresponding query.
So basically what i have is a client database and when I have a particular clients record open i want to be able to date a box and the word document open up and automatically fill with the information pertaining to that client that is stored on a query. I dont need it to save the file or anything like that. Just open a completed form so we can print it and close it again.
I have managed to connect the word document to the datebox and have it open. but i cant get the information to fill in.
Im pretty new to Visual Basics and trying to update a database that someone else created long ago so have used a tutoral online to create this (be kind to me)
I have followed the instructions for inserting bookmarks into the word document and then wrote the code in visual basic but i keep getting the error "The Range Cannot Be Deleted"
Can some one help me figure out where i am going wrong please?
Code is as follows:
Sub F4FundingReport()
Dim wApp As Word.Application
Dim wDoc As Word.Document
Dim rs As DAO.Recordset
Set wApp = Word.Application
Set wDoc = wApp.Documents.Open("\\knetapp1b\data\Care And Repair\Aids and Adaptations 2010\Word\F4 Funding Report Jan21.doc")
Set rs = CurrentDb.OpenRecordset("QRY_F4FundingReport")
If Not rs.EOF Then rs.MoveFirst
Do Until rs.EOF
wDoc.Bookmarks("ReferralID").Range.Text = (rs!ReferralID)
wDoc.Bookmarks("Title").Range.Text = (rs!Client1Title)
wDoc.Bookmarks("FirstName").Range.Text = (rs!Client1Forename)
wDoc.Bookmarks("Surname").Range.Text = (rs!Client1Surname)
wDoc.Bookmarks("Address1").Range.Text = (rs!ClientAddress1)
wDoc.Bookmarks("Address2").Range.Text = (rs!ClientAddress2)
wDoc.Bookmarks("Town").Range.Text = (rs!ClientTown)
wDoc.Bookmarks("County").Range.Text = (rs!ClientCounty)
wDoc.Bookmarks("Postcode").Range.Text = (rs!ClientPostcode)
wDoc.Bookmarks("OTWorksDescription").Range.Text = (rs!OTWorksDescription)
wDoc.Bookmarks("F4TotalCosts").Range.Text = (rs!F4TotalWorksQuote)
wDoc.Bookmarks("AnticipatedGrant").Range.Text = (rs!AnticipatedGrant%)
wDoc.Bookmarks("EstimatedGrantAmount").Range.Text = (rs!EstimatedGrantAward£)
wDoc.Bookmarks("AnticipatedBTS").Range.Text = (rs!AnticipatedBTSAward%)
wDoc.Bookmarks("EstimatedBTSAmount").Range.Text = (rs!EstimatedBTSAward£)
wDoc.Bookmarks("TitleFees1").Range.Text = (rs!TitleSearchFee)
wDoc.Bookmarks("Contractor1").Range.Text = (rs!Contractor)
wDoc.Bookmarks("Titlefee2").Range.Text = (rs!TitleSearchFee)
wDoc.Bookmarks("ClientShare1").Range.Text = (rs!ClientShare)
wDoc.Bookmarks("ClientShare2").Range.Text = (rs!ClientShare)
wDoc.Bookmarks("Contractor2").Range.Text = (rs!Contractor)
Loop
End Sub
I am having a bit of trouble trying to get a Word Document to open from access and autofill with the information from a corresponding query.
So basically what i have is a client database and when I have a particular clients record open i want to be able to date a box and the word document open up and automatically fill with the information pertaining to that client that is stored on a query. I dont need it to save the file or anything like that. Just open a completed form so we can print it and close it again.
I have managed to connect the word document to the datebox and have it open. but i cant get the information to fill in.
Im pretty new to Visual Basics and trying to update a database that someone else created long ago so have used a tutoral online to create this (be kind to me)
I have followed the instructions for inserting bookmarks into the word document and then wrote the code in visual basic but i keep getting the error "The Range Cannot Be Deleted"
Can some one help me figure out where i am going wrong please?
Code is as follows:
Sub F4FundingReport()
Dim wApp As Word.Application
Dim wDoc As Word.Document
Dim rs As DAO.Recordset
Set wApp = Word.Application
Set wDoc = wApp.Documents.Open("\\knetapp1b\data\Care And Repair\Aids and Adaptations 2010\Word\F4 Funding Report Jan21.doc")
Set rs = CurrentDb.OpenRecordset("QRY_F4FundingReport")
If Not rs.EOF Then rs.MoveFirst
Do Until rs.EOF
wDoc.Bookmarks("ReferralID").Range.Text = (rs!ReferralID)
wDoc.Bookmarks("Title").Range.Text = (rs!Client1Title)
wDoc.Bookmarks("FirstName").Range.Text = (rs!Client1Forename)
wDoc.Bookmarks("Surname").Range.Text = (rs!Client1Surname)
wDoc.Bookmarks("Address1").Range.Text = (rs!ClientAddress1)
wDoc.Bookmarks("Address2").Range.Text = (rs!ClientAddress2)
wDoc.Bookmarks("Town").Range.Text = (rs!ClientTown)
wDoc.Bookmarks("County").Range.Text = (rs!ClientCounty)
wDoc.Bookmarks("Postcode").Range.Text = (rs!ClientPostcode)
wDoc.Bookmarks("OTWorksDescription").Range.Text = (rs!OTWorksDescription)
wDoc.Bookmarks("F4TotalCosts").Range.Text = (rs!F4TotalWorksQuote)
wDoc.Bookmarks("AnticipatedGrant").Range.Text = (rs!AnticipatedGrant%)
wDoc.Bookmarks("EstimatedGrantAmount").Range.Text = (rs!EstimatedGrantAward£)
wDoc.Bookmarks("AnticipatedBTS").Range.Text = (rs!AnticipatedBTSAward%)
wDoc.Bookmarks("EstimatedBTSAmount").Range.Text = (rs!EstimatedBTSAward£)
wDoc.Bookmarks("TitleFees1").Range.Text = (rs!TitleSearchFee)
wDoc.Bookmarks("Contractor1").Range.Text = (rs!Contractor)
wDoc.Bookmarks("Titlefee2").Range.Text = (rs!TitleSearchFee)
wDoc.Bookmarks("ClientShare1").Range.Text = (rs!ClientShare)
wDoc.Bookmarks("ClientShare2").Range.Text = (rs!ClientShare)
wDoc.Bookmarks("Contractor2").Range.Text = (rs!Contractor)
Loop
End Sub