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 derfloh on being selected by the Tek-Tips community for having the most helpful posts in the forums last week. Way to Go!

Cannot generate word document twice from access

Status
Not open for further replies.

pingit

MIS
Nov 24, 2003
37
NZ
Hello All
I have an access database that opens a word template as a word document, fills in some bookmarked textbox's then queries the database and adds and fills in row of a table. the problem I have is I cannot perform the document fill twice. if I close the document(saved or not) I cannot run the code again to create the full document (the code gets stuck on the table. The only way I cen get the complete document is to close and open the database again. I think Access may be keeping some data but what I don't know
Any help would be much appreciated?
 
Be sure your code use always full qualified word objects.

Hope This Helps, PH.
FAQ219-2884
FAQ181-2886
 
Hello thanks for the reply. not sure what is meant by ful qualified word objects. Here is the code for filling in the doc
Set appWord = GetObject(, "Word.application")
If Err = 429 Then
Set appWord = New Word.Application
With appWord
.Visible = True
.WindowState = wdWindowStateMaximize
.Documents.Add Template:=(conTEMPLATE_NAME)
.ActiveDocument.Bookmarks("Supplier").Select
.Application.Selection.Text = strTotalName
.ActiveDocument.Bookmarks("SSID").Select
.Application.Selection.Text = strSSID
.ActiveDocument.Bookmarks("TodayDate").Select
.Application.Selection.Text = strDate
.ActiveDocument.Bookmarks("ACCpo").Select
.Application.Selection.Text = ACCpo
.ActiveDocument.Bookmarks("ClaimantN").Select
.Application.Selection.Text = strCname
.ActiveDocument.Bookmarks("ClaimantAd").Select
.Application.Selection.Text = strCaddress
.ActiveDocument.Bookmarks("ClaimNo").Select
.Application.Selection.Text = strCNO
.ActiveDocument.Bookmarks("CaseManager").Select
.Application.Selection.Text = strCMname
.ActiveDocument.Bookmarks("SSIDTable").Select
Selection.InsertRowsBelow 1
With rst
Do While Not .EOF
Selection.TypeText Text:=![ServiceItemCode]
Selection.MoveRight Unit:=wdCell
Selection.TypeText Text:=![ServiceItemDescription]
Selection.MoveRight Unit:=wdCell
Selection.FormFields.Add Selection.Range, wdFieldFormTextInput
Selection.MoveRight Unit:=wdCell
Selection.FormFields.Add Selection.Range, wdFieldFormTextInput
Selection.MoveRight Unit:=wdCell
Selection.FormFields.Add Selection.Range, wdFieldFormTextInput
Selection.MoveRight Unit:=wdCell
.MoveNext
Loop
Selection.MoveRight Unit:=wdCell
Selection.MoveRight Unit:=wdCell
Selection.MoveRight Unit:=wdCell
Selection.TypeText "Total:"
.Close
End With
End With
Err = 0
End If

 
All lines beginning with Selection. should looks like appWord.Selection. (ie the word Selection object should be full qualified).

Hope This Helps, PH.
FAQ219-2884
FAQ181-2886
 
I do not think that you want this:

[tt]Set appWord = GetObject(, "Word.application")
If Err = 429 Then
Set appWord = New Word.Application
With appWord[/tt]

In quite that order. The code will never run if Word is open, you need to move End If from the bottom of the code to just before

[tt] With appWord[/tt]
 
Thanks to PHV and Remou I have applied both your recommendations and the problem is gone. Thanks again
 
Status
Not open for further replies.

Part and Inventory Search

Sponsor

Back
Top