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

Can't quite persuade it to work

Status
Not open for further replies.

Steven811

Technical User
Apr 15, 2004
76
GB
Hi

Although A2k limits the use of nesting subforms to 3 levels and this increases to 7 for 2002 and 2003 I can't get the code to work.

On another PC I have A2002, I converted the db and it all seems to work fine. When I run the merge I still can't seem to get past the 2nd subform to copy the record set from the final subform.

Any tips would be very welcome.

Steven811

The full code is as follows:

Code:

[Private Sub MergeButton_Click()
On Error GoTo MergeButton_Err

Dim objWord As Word.Application


'Start Microsoft Word.
Set objWord = CreateObject("Word.Application")

With objWord
'Make the application visible.
.Visible = True

'Open the document.
.Documents.Open ("C:\MyMerge.doc")

'Move to each bookmark and insert text from the form.
.ActiveDocument.Bookmarks("CompanyName").Select
.Selection.Text = (CStr(Forms!MainForm!FieldName))


'Move to each bookmark and insert text from the form.
.ActiveDocument.Bookmarks("SiteName").Select
.Selection.Text = (CStr(Me!subForm1.Form!FieldName1))

.ActiveDocument.Bookmarks("cboDesignation").Select
.Selection.Text = (CStr(Me!subForm1.Form!FieldName2))

.ActiveDocument.Bookmarks("SiteAddress1").Select
.Selection.Text = (CStr(Me.subForm1.Form!FieldName3))


.ActiveDocument.Bookmarks("cboManager").Select
.Selection.Text = (CStr(Me!subForm1.Form!subForm2.Form!FieldName4))

.ActiveDocument.Bookmarks("Contact11stName").Select
.Selection.Text = (CStr(Me!subForm1.Form!subForm2.Form!FieldName5))

.ActiveDocument.Bookmarks("Contact12ndName").Select
.Selection.Text = (CStr(Me!subForm1.Form!subForm2.Form!FieldName6))

.ActiveDocument.Bookmarks("JobNo").Select
.Selection.Text = (CStr(Me!subForm1.Form!subForm2.Form!subForm3.Form!FieldName7))


.ActiveDocument.Bookmarks("DateofComment").Select
.Selection.Text = (CStr(Me!subForm1.Form!subForm2.Form!subForm3.Form!subForm4.Form!FieldName8))


End With

'Print the document in the foreground so Microsoft Word will not close
'until the document finishes printing.
' objWord.ActiveDocument.PrintOut Background:=False

'Close the document without saving changes.
' objWord.ActiveDocument.Close SaveChanges:=wdDoNotSaveChanges
'
' 'Quit Microsoft Word and release the object variable.
' objWord.Quit
' Set objWord = Nothing
' Exit Sub]
 
Works on my a2k setup (just had to test, I usually don't use more than one level of subforms).

Would you mind giving some more precise information than "can't get the code to work.", faq181-2886 #14 explains a little about that.

What errormessages, what happens if you do a debug.print of some of the values from the third (or fourth) subform.

You say there's a limit of three, but here you refer four levels, which I'm also able to refer on my a2k setup.

My guess, is that one of the refererences, probably to one of the "last" subform is incorrect. From the main form, enter the controlsource of one of the controls. Use the expression builder, and doubleclick thru forms, loaded forms, main form, subform1, subform2, subform3, subform4 and a control on the "last" subform. This should give the correct reference, that can be used in the code.

Do use either msgbox or debug.print to verify you're able to get the values from the references.

Roy-Vidar
 
Hi Roy

Thanks for taking a look.

I use Debug, Compile and there are no error messages.

When I view the merged Word document the bookmarks are replaced with the data from Access, up to the 3rd level of form. After this the bookmarks remain intact and the merge does not complete, there are no error messages.

Good idea to use the expression builder to make sure I was using the correct names, hadn't thought of that as I tend not/can't use the expression builder.

To cut a long story short, the expression builder has shown me that the form name I was using was incorrect. Changed it and it worked like a charm.

Does raise the question about the limitiations that MS claim in their Help about A2k being restricted to 3 levels of form, this seems to work to the 4th level.

Thanks

Steven811

 
Status
Not open for further replies.

Part and Inventory Search

Sponsor

Back
Top