Tek-Tips is the largest IT community on the Internet today!

Members share and learn making Tek-Tips Forums the best source of peer-reviewed technical information on the Internet!

  • Congratulations gkittelson on being selected by the Tek-Tips community for having the most helpful posts in the forums last week. Way to Go!

automation of word via Access

Status
Not open for further replies.

cneill

Instructor
Mar 18, 2003
210
GB
Can anyone help me change the coding to allow me to either use a dlook up or collect the Address information from a form

Dim WordObj As Word.Application
Dim WordDoc As Word.Document
Dim WordRange As Word.Range
Set WordObj = CreateObject("Word.Application")
Set WordDoc = WordObj.Documents.Open _
("C:\Documents and Settings\Compaq_Owner\My Documents\Dee\Houses\SET UP DOCS\Housing Benefit Authorisation Form May 2011.docx")
WordObj.Visible = True

' Go to the bookmark named "Address"
Set WordRange = WordDoc.Goto(What:=wdGoToBookmark, Name:="Address")
WordRange.InsertAfter "66 Alexandra Road"

Many thanks for your help
neill
 
how about
Code:
WordRange.InsertAfter froms!formname!controlname

or

Code:
WordRange.InsertAfter dlookup("Somefield","sometable","somecondition")
 
thanks everyone, that is great, one more question, how could I reference the fields in a query, instead of using lots of dlookups?

thanks
cneill
 
Code:
dim mydb as database 
dim rst as recordset
dim sqlstr as string
set mydb=currentdb
sqlstr = "select addressfield from queryname where somecondition=" & somevalule
WordRange.InsertAfter mydb.openrecordset(sqlstr)!addressfield
 
PWise

Excellent I will try this tonight, I will let you know how I get on.

Thanks
CNEILL
 
Hi,

I am still leaning how to do this, so I think I need a bit more help
I tried this
sqlstr = "select HouseAddress from QryHousingBenefit where HID=" & [Forms]![FrmSchemes]![HousesAttached]
Debug.Print sqlstr
Set WordRange = WordDoc.Goto(What:=wdGoToBookmark, Name:="HouseAddress")
WordRange.InsertAfter mydb.OpenRecordset(sqlstr)!HouseAddress

but it is not returning the right value, the debug.print sqlstr
is giving me select HouseAddress from QryHousingBenefit where HID=9 and it stops at the wordrange.insertafter and tells me that there is a runtime error 3061 To few parameters.Expected 1

can you help please?

Thanks CNEILL
 
what do you get when you run the query in a query Sql window
 
Hi Pwise,
sorry how do I do that? I am still new to this?

thanks

cneill
 
Status
Not open for further replies.

Part and Inventory Search

Sponsor

Back
Top