"For Loop" Mail Merge

after68

New member
Local time
Today, 17:11
Joined
Dec 17, 2007
Messages
8
Hello all. I am at my wit's end. I am a VB retard and need a little help. I have an access database that works great until I want to mail merge to a word document. I have 40 text boxes that I want to merge along with 35 checkboxes. I bookmarked my document with the exact names of my text boxes and checkboxes and can mail merge just fine. However, can I write a for loop since everything is named like:
textboxes = txt_frm_1 - txt_frm_40
checkboxes = cb_frm_1 - cb_frm_35​
I would like to get 170 lines of code down to like 30 if possible. Someone suggested a for loop and I have no Idea how to write one. I have looked all over the net and understand maybe 2% of what I see, so any help would be much appreciated
 
Can you post the code you have so I can see what you are trying to do?

I had a big problem trying to merge to word on one of my databases. I found the easiest way was to replicate the word doc into the detail section of an access report. Works a treat!
 
'late binding
Dim MyWord As Object
Set MyWord = CreateObject("Word.Application")


'early binding
'Dim MyWord As Word.Application
'Set MyWord = New Word.Application


'Dim MyWord As Word.Application
'Set MyWord = New Word.Application

'Dim PathDocu As String

'If Me.NomPers <> "" And Me.Prénom <> "" Then
With MyWord
'.Documents.Open (PathDocu & "HP_Assessment_new.doc")

'.WindowState = 1


'Make the application visible.
.Visible = True
.Activate
Set oDoc = MyWord.Documents.Open("c:\newdoc")
'oDoc.Range.Text = "Hi"

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

'.ActiveDocument.Bookmarks("building_age").Range.Text'


'.ActiveDocument.Bookmarks.Select'
'.Selection.Text = " Build "

'Move to each bookmark and insert text from the form.
.ActiveDocument.Bookmarks("txt_cust_5").Select
.Selection.Text = (CStr(Forms!customer_subform!txt_cust_5 & ""))
.ActiveDocument.Bookmarks("txt_cust_12").Select
.Selection.Text = (CStr(Forms!customer_subform!txt_cust_12 & ""))
.ActiveDocument.Bookmarks("txt_asses_1").Select
.Selection.Text = (CStr(Forms!customer_subform!assesment_subform!txt_asses_1 & ""))
.ActiveDocument.Bookmarks("txt_asses_2").Select
.Selection.Text = (CStr(Forms!customer_subform!assesment_subform!txt_asses_2 & ""))
.ActiveDocument.Bookmarks("txt_asses_3").Select
.Selection.Text = (CStr(Forms!customer_subform!assesment_subform!txt_asses_3 & ""))
.ActiveDocument.Bookmarks("txt_asses_4").Select
.Selection.Text = (CStr(Forms!customer_subform!assesment_subform!txt_asses_4 & ""))
.ActiveDocument.Bookmarks("txt_asses_5").Select
.Selection.Text = (CStr(Forms!customer_subform!assesment_subform!txt_asses_5 & ""))
.ActiveDocument.Bookmarks("txt_asses_6").Select
.Selection.Text = (CStr(Forms!customer_subform!assesment_subform!txt_asses_6 & ""))
.ActiveDocument.Bookmarks("txt_asses_7").Select
.Selection.Text = (CStr(Forms!customer_subform!assesment_subform!txt_asses_7 & ""))
.ActiveDocument.Bookmarks("txt_asses_8").Select
.Selection.Text = (CStr(Forms!customer_subform!assesment_subform!txt_asses_8 & ""))
.ActiveDocument.Bookmarks("txt_asses_9").Select
.Selection.Text = (CStr(Forms!customer_subform!assesment_subform!txt_asses_9 & ""))
.ActiveDocument.Bookmarks("txt_asses_10").Select
.Selection.Text = (CStr(Forms!customer_subform!assesment_subform!txt_asses_10 & ""))
.ActiveDocument.Bookmarks("txt_asses_11").Select
.Selection.Text = (CStr(Forms!customer_subform!assesment_subform!txt_asses_11 & ""))
.ActiveDocument.Bookmarks("txt_asses_12").Select
.Selection.Text = (CStr(Forms!customer_subform!assesment_subform!txt_asses_12 & ""))
.ActiveDocument.Bookmarks("txt_asses_13").Select
.Selection.Text = (CStr(Forms!customer_subform!assesment_subform!txt_asses_13 & ""))
.ActiveDocument.Bookmarks("txt_asses_14").Select
.Selection.Text = (CStr(Forms!customer_subform!assesment_subform!txt_asses_14 & ""))
.ActiveDocument.Bookmarks("txt_asses_15").Select
.Selection.Text = (CStr(Forms!customer_subform!assesment_subform!txt_asses_15 & ""))
.ActiveDocument.Bookmarks("txt_asses_16").Select
.Selection.Text = (CStr(Forms!customer_subform!assesment_subform!txt_asses_16 & ""))
.ActiveDocument.Bookmarks("txt_asses_17").Select
.Selection.Text = (CStr(Forms!customer_subform!assesment_subform!txt_asses_17 & ""))
.ActiveDocument.Bookmarks("txt_asses_18").Select
.Selection.Text = (CStr(Forms!customer_subform!assesment_subform!txt_asses_18 & ""))
.ActiveDocument.Bookmarks("txt_asses_19").Select
.Selection.Text = (CStr(Forms!customer_subform!assesment_subform!txt_asses_19 & ""))
.ActiveDocument.Bookmarks("txt_asses_20").Select
.Selection.Text = (CStr(Forms!customer_subform!assesment_subform!txt_asses_20 & ""))
.ActiveDocument.Bookmarks("txt_asses_21").Select
.Selection.Text = (CStr(Forms!customer_subform!assesment_subform!txt_asses_21 & ""))
.ActiveDocument.Bookmarks("txt_asses_22").Select
.Selection.Text = (CStr(Forms!customer_subform!assesment_subform!txt_asses_22 & ""))
.ActiveDocument.Bookmarks("txt_asses_23").Select
.Selection.Text = (CStr(Forms!customer_subform!assesment_subform!txt_asses_23 & ""))
.ActiveDocument.Bookmarks("txt_asses_24").Select
.Selection.Text = (CStr(Forms!customer_subform!assesment_subform!txt_asses_24 & ""))
.ActiveDocument.Bookmarks("txt_asses_25").Select
.Selection.Text = (CStr(Forms!customer_subform!assesment_subform!txt_asses_25 & ""))
.ActiveDocument.Bookmarks("txt_asses_26").Select
.Selection.Text = (CStr(Forms!customer_subform!assesment_subform!txt_asses_26 & ""))
.ActiveDocument.Bookmarks("txt_asses_27").Select
.Selection.Text = (CStr(Forms!customer_subform!assesment_subform!txt_asses_27 & ""))
.ActiveDocument.Bookmarks("txt_asses_28").Select
.Selection.Text = (CStr(Forms!customer_subform!assesment_subform!txt_asses_28 & ""))
.ActiveDocument.Bookmarks("txt_asses_29").Select
.Selection.Text = (CStr(Forms!customer_subform!assesment_subform!txt_asses_29 & ""))
.ActiveDocument.Bookmarks("txt_asses_30").Select
.Selection.Text = (CStr(Forms!customer_subform!assesment_subform!txt_asses_30 & ""))
.ActiveDocument.Bookmarks("txt_asses_31").Select
.Selection.Text = (CStr(Forms!customer_subform!assesment_subform!txt_asses_31 & ""))
.ActiveDocument.Bookmarks("txt_asses_32").Select
.Selection.Text = (CStr(Forms!customer_subform!assesment_subform!txt_asses_32 & ""))
.ActiveDocument.Bookmarks("txt_asses_33").Select
.Selection.Text = (CStr(Forms!customer_subform!assesment_subform!txt_asses_33 & ""))
.ActiveDocument.Bookmarks("txt_asses_34").Select
.Selection.Text = (CStr(Forms!customer_subform!assesment_subform!txt_asses_34 & ""))
.ActiveDocument.Bookmarks("txt_asses_35").Select
.Selection.Text = (CStr(Forms!customer_subform!assesment_subform!txt_asses_35 & ""))
.ActiveDocument.Bookmarks("txt_asses_36").Select
.Selection.Text = (CStr(Forms!customer_subform!assesment_subform!txt_asses_36 & ""))
.ActiveDocument.Bookmarks("txt_asses_37").Select
.Selection.Text = (CStr(Forms!customer_subform!assesment_subform!txt_asses_37 & ""))
.ActiveDocument.Bookmarks("txt_asses_38").Select
.Selection.Text = (CStr(Forms!customer_subform!assesment_subform!txt_asses_38 & ""))
.ActiveDocument.Bookmarks("txt_asses_39").Select
.Selection.Text = (CStr(Forms!customer_subform!assesment_subform!txt_asses_39 & ""))
.ActiveDocument.Bookmarks("txt_asses_40").Select
.Selection.Text = (CStr(Forms!customer_subform!assesment_subform!txt_asses_40 & ""))
.ActiveDocument.Bookmarks("txt_asses_41").Select
.Selection.Text = (CStr(Forms!customer_subform!assesment_subform!txt_asses_41 & ""))
.ActiveDocument.Bookmarks("txt_asses_42").Select
.Selection.Text = (CStr(Forms!customer_subform!assesment_subform!txt_asses_42 & ""))
.ActiveDocument.Bookmarks("txt_asses_43").Select
.Selection.Text = (CStr(Forms!customer_subform!assesment_subform!txt_asses_43 & ""))
.ActiveDocument.Bookmarks("txt_asses_44").Select
.Selection.Text = (CStr(Forms!customer_subform!assesment_subform!txt_asses_44 & ""))
.ActiveDocument.Bookmarks("txt_asses_45").Select
.Selection.Text = (CStr(Forms!customer_subform!assesment_subform!txt_asses_45 & ""))
.ActiveDocument.Bookmarks("txt_asses_46").Select
.Selection.Text = (CStr(Forms!customer_subform!assesment_subform!txt_asses_46 & ""))
.ActiveDocument.Bookmarks("txt_asses_47").Select
.Selection.Text = (CStr(Forms!customer_subform!assesment_subform!txt_asses_47 & ""))
.ActiveDocument.Bookmarks("txt_asses_48").Select
.Selection.Text = (CStr(Forms!customer_subform!assesment_subform!txt_asses_48 & ""))
.ActiveDocument.Bookmarks("txt_asses_49").Select
.Selection.Text = (CStr(Forms!customer_subform!assesment_subform!txt_asses_49 & ""))
.ActiveDocument.Bookmarks("txt_asses_50").Select
.Selection.Text = (CStr(Forms!customer_subform!assesment_subform!txt_asses_50 & ""))
.ActiveDocument.Bookmarks("txt_asses_51").Select
.Selection.Text = (CStr(Forms!customer_subform!assesment_subform!txt_asses_51 & ""))
.ActiveDocument.Bookmarks("txt_asses_52").Select
.Selection.Text = (CStr(Forms!customer_subform!assesment_subform!txt_asses_52 & ""))
.ActiveDocument.Bookmarks("txt_asses_53").Select
.Selection.Text = (CStr(Forms!customer_subform!assesment_subform!txt_asses_53 & ""))
.ActiveDocument.Bookmarks("txt_asses_54").Select
.Selection.Text = (CStr(Forms!customer_subform!assesment_subform!txt_asses_54 & ""))
.ActiveDocument.Bookmarks("txt_asses_55").Select
.Selection.Text = (CStr(Forms!customer_subform!assesment_subform!txt_asses_55 & ""))
.ActiveDocument.Bookmarks("txt_asses_56").Select
.Selection.Text = (CStr(Forms!customer_subform!assesment_subform!txt_asses_56 & ""))
.ActiveDocument.Bookmarks("txt_asses_57").Select
.Selection.Text = (CStr(Forms!customer_subform!assesment_subform!txt_asses_57 & ""))
.ActiveDocument.Bookmarks("txt_asses_58").Select
.Selection.Text = (CStr(Forms!customer_subform!assesment_subform!txt_asses_58 & ""))
.ActiveDocument.Bookmarks("txt_asses_59").Select
.Selection.Text = (CStr(Forms!customer_subform!assesment_subform!txt_asses_59 & ""))
.ActiveDocument.Bookmarks("txt_asses_60").Select
.Selection.Text = (CStr(Forms!customer_subform!assesment_subform!txt_asses_60 & ""))
.ActiveDocument.Bookmarks("txt_asses_61").Select
.Selection.Text = (CStr(Forms!customer_subform!assesment_subform!txt_asses_61 & ""))
.ActiveDocument.Bookmarks("txt_asses_62").Select
.Selection.Text = (CStr(Forms!customer_subform!assesment_subform!txt_asses_62 & ""))
.ActiveDocument.Bookmarks("txt_asses_63").Select
.Selection.Text = (CStr(Forms!customer_subform!assesment_subform!txt_asses_63 & ""))
.ActiveDocument.Bookmarks("txt_asses_64").Select
.Selection.Text = (CStr(Forms!customer_subform!assesment_subform!txt_asses_64 & ""))
.ActiveDocument.Bookmarks("txt_asses_65").Select
.Selection.Text = (CStr(Forms!customer_subform!assesment_subform!txt_asses_65 & ""))
.ActiveDocument.Bookmarks("txt_asses_66").Select
.Selection.Text = (CStr(Forms!customer_subform!assesment_subform!txt_asses_66 & ""))
.ActiveDocument.Bookmarks("txt_asses_67").Select
.Selection.Text = (CStr(Forms!customer_subform!assesment_subform!txt_asses_67 & ""))
.ActiveDocument.Bookmarks("txt_asses_68").Select
.Selection.Text = (CStr(Forms!customer_subform!assesment_subform!txt_asses_68 & ""))
.ActiveDocument.Bookmarks("txt_asses_69").Select
.Selection.Text = (CStr(Forms!customer_subform!assesment_subform!txt_asses_69 & ""))
.ActiveDocument.Bookmarks("txt_asses_70").Select
.Selection.Text = (CStr(Forms!customer_subform!assesment_subform!txt_asses_70 & ""))
.ActiveDocument.Bookmarks("txt_asses_71").Select
.Selection.Text = (CStr(Forms!customer_subform!assesment_subform!txt_asses_71 & ""))
.ActiveDocument.Bookmarks("txt_asses_72").Select
.Selection.Text = (CStr(Forms!customer_subform!assesment_subform!txt_asses_72 & ""))
.ActiveDocument.Bookmarks("txt_asses_73").Select
.Selection.Text = (CStr(Forms!customer_subform!assesment_subform!txt_asses_73 & ""))
.ActiveDocument.Bookmarks("txt_asses_74").Select
.Selection.Text = (CStr(Forms!customer_subform!assesment_subform!txt_asses_74 & ""))
.ActiveDocument.Bookmarks("txt_asses_75").Select
.Selection.Text = (CStr(Forms!customer_subform!assesment_subform!txt_asses_75 & ""))
.ActiveDocument.Bookmarks("txt_asses_76").Select
.Selection.Text = (CStr(Forms!customer_subform!assesment_subform!txt_asses_76 & ""))
.ActiveDocument.Bookmarks("txt_asses_77").Select
.Selection.Text = (CStr(Forms!customer_subform!assesment_subform!txt_asses_77 & ""))
.ActiveDocument.Bookmarks("txt_asses_78").Select
.Selection.Text = (CStr(Forms!customer_subform!assesment_subform!txt_asses_78 & ""))
.ActiveDocument.Bookmarks("txt_asses_79").Select
.Selection.Text = (CStr(Forms!customer_subform!assesment_subform!txt_asses_79 & ""))
.ActiveDocument.Bookmarks("txt_asses_80").Select
.Selection.Text = (CStr(Forms!customer_subform!assesment_subform!txt_asses_80 & ""))
.ActiveDocument.Bookmarks("txt_asses_81").Select
.Selection.Text = (CStr(Forms!customer_subform!assesment_subform!txt_asses_81 & ""))
.ActiveDocument.Bookmarks("txt_asses_82").Select
.Selection.Text = (CStr(Forms!customer_subform!assesment_subform!txt_asses_82 & ""))
.ActiveDocument.Bookmarks("txt_asses_83").Select
.Selection.Text = (CStr(Forms!customer_subform!assesment_subform!txt_asses_83 & ""))
.ActiveDocument.Bookmarks("txt_asses_84").Select
.Selection.Text = (CStr(Forms!customer_subform!assesment_subform!txt_asses_84 & ""))
.ActiveDocument.Bookmarks("txt_asses_85").Select
.Selection.Text = (CStr(Forms!customer_subform!assesment_subform!txt_asses_85 & ""))
.ActiveDocument.Bookmarks("txt_asses_86").Select
.Selection.Text = (CStr(Forms!customer_subform!assesment_subform!txt_asses_86 & ""))
.ActiveDocument.Bookmarks("txt_asses_87").Select
.Selection.Text = (CStr(Forms!customer_subform!assesment_subform!txt_asses_87 & ""))
.ActiveDocument.Bookmarks("txt_asses_88").Select
.Selection.Text = (CStr(Forms!customer_subform!assesment_subform!txt_asses_88 & ""))
.ActiveDocument.Bookmarks("txt_asses_89").Select
.Selection.Text = (CStr(Forms!customer_subform!assesment_subform!txt_asses_89 & ""))
.ActiveDocument.Bookmarks("txt_cust_100").Select
.Selection.Text = (CStr(Forms!customer_subform!txt_cust_100 & ""))

'checkbox merg'
If (CStr(Forms!customer_subform!assesment_subform!cb_asses_1 & "")) Then
.ActiveDocument.FormFields("cb_asses_1").CheckBox.Value = True
End If
If (CStr(Forms!customer_subform!assesment_subform!cb_asses_2)) Then
.ActiveDocument.FormFields("cb_asses_2").CheckBox.Value = True
End If
If (CStr(Forms!customer_subform!assesment_subform!cb_asses_3)) Then
.ActiveDocument.FormFields("cb_asses_3").CheckBox.Value = True
End If
If (CStr(Forms!customer_subform!assesment_subform!cb_asses_4)) Then
.ActiveDocument.FormFields("cb_asses_4").CheckBox.Value = True
End If
If (CStr(Forms!customer_subform!assesment_subform!cb_asses_5)) Then
.ActiveDocument.FormFields("cb_asses_5").CheckBox.Value = True
End If
If (CStr(Forms!customer_subform!assesment_subform!cb_asses_6)) Then
.ActiveDocument.FormFields("cb_asses_6").CheckBox.Value = True
End If
If (CStr(Forms!customer_subform!assesment_subform!cb_asses_7)) Then
.ActiveDocument.FormFields("cb_asses_7").CheckBox.Value = True
End If
If (CStr(Forms!customer_subform!assesment_subform!cb_asses_8)) Then
.ActiveDocument.FormFields("cb_asses_8").CheckBox.Value = True
End If
If (CStr(Forms!customer_subform!assesment_subform!cb_asses_9)) Then
.ActiveDocument.FormFields("cb_asses_9").CheckBox.Value = True
End If
If (CStr(Forms!customer_subform!assesment_subform!cb_asses_10)) Then
.ActiveDocument.FormFields("cb_asses_10").CheckBox.Value = True
End If
If (CStr(Forms!customer_subform!assesment_subform!cb_asses_11)) Then
.ActiveDocument.FormFields("cb_asses_11").CheckBox.Value = True
End If
If (CStr(Forms!customer_subform!assesment_subform!cb_asses_12)) Then
.ActiveDocument.FormFields("cb_asses_12").CheckBox.Value = True
End If
If (CStr(Forms!customer_subform!assesment_subform!cb_asses_13)) Then
.ActiveDocument.FormFields("cb_asses_13").CheckBox.Value = True
End If
If (CStr(Forms!customer_subform!assesment_subform!cb_asses_14)) Then
.ActiveDocument.FormFields("cb_asses_14").CheckBox.Value = True
End If
If (CStr(Forms!customer_subform!assesment_subform!cb_asses_15)) Then
.ActiveDocument.FormFields("cb_asses_15").CheckBox.Value = True
End If
If (CStr(Forms!customer_subform!assesment_subform!cb_asses_16)) Then
.ActiveDocument.FormFields("cb_asses_16").CheckBox.Value = True
End If
If (CStr(Forms!customer_subform!assesment_subform!cb_asses_17)) Then
.ActiveDocument.FormFields("cb_asses_17").CheckBox.Value = True
End If
If (CStr(Forms!customer_subform!assesment_subform!cb_asses_18)) Then
.ActiveDocument.FormFields("cb_asses_18").CheckBox.Value = True
End If
If (CStr(Forms!customer_subform!assesment_subform!cb_asses_19)) Then
.ActiveDocument.FormFields("cb_asses_19").CheckBox.Value = True
End If
If (CStr(Forms!customer_subform!assesment_subform!cb_asses_20)) Then
.ActiveDocument.FormFields("cb_asses_20").CheckBox.Value = True
End If
If (CStr(Forms!customer_subform!assesment_subform!cb_asses_21)) Then
.ActiveDocument.FormFields("cb_asses_21").CheckBox.Value = True
End If
If (CStr(Forms!customer_subform!assesment_subform!cb_asses_22)) Then
.ActiveDocument.FormFields("cb_asses_22").CheckBox.Value = True
End If
If (CStr(Forms!customer_subform!assesment_subform!cb_asses_23)) Then
.ActiveDocument.FormFields("cb_asses_23").CheckBox.Value = True
End If
If (CStr(Forms!customer_subform!assesment_subform!cb_asses_24)) Then
.ActiveDocument.FormFields("cb_asses_24").CheckBox.Value = True
End If
If (CStr(Forms!customer_subform!assesment_subform!cb_asses_25)) Then
.ActiveDocument.FormFields("cb_asses_25").CheckBox.Value = True
End If
If (CStr(Forms!customer_subform!assesment_subform!cb_asses_26)) Then
.ActiveDocument.FormFields("cb_asses_26").CheckBox.Value = True
End If
If (CStr(Forms!customer_subform!assesment_subform!cb_asses_27)) Then
.ActiveDocument.FormFields("cb_asses_27").CheckBox.Value = True
End If
If (CStr(Forms!customer_subform!assesment_subform!cb_asses_28)) Then
.ActiveDocument.FormFields("cb_asses_28").CheckBox.Value = True
End If
If (CStr(Forms!customer_subform!assesment_subform!cb_asses_29)) Then
.ActiveDocument.FormFields("cb_asses_29").CheckBox.Value = True
End If
If (CStr(Forms!customer_subform!assesment_subform!cb_asses_30)) Then
.ActiveDocument.FormFields("cb_asses_30").CheckBox.Value = True
End If
If (CStr(Forms!customer_subform!assesment_subform!cb_asses_31)) Then
.ActiveDocument.FormFields("cb_asses_31").CheckBox.Value = True
End If
If (CStr(Forms!customer_subform!assesment_subform!cb_asses_32)) Then
.ActiveDocument.FormFields("cb_asses_32").CheckBox.Value = True
End If
If (CStr(Forms!customer_subform!assesment_subform!cb_asses_33)) Then
.ActiveDocument.FormFields("cb_asses_33").CheckBox.Value = True
End If
If (CStr(Forms!customer_subform!assesment_subform!cb_asses_34)) Then
.ActiveDocument.FormFields("cb_asses_34").CheckBox.Value = True
End If
If (CStr(Forms!customer_subform!assesment_subform!cb_asses_35)) Then
.ActiveDocument.FormFields("cb_asses_35").CheckBox.Value = True
End If
If (CStr(Forms!customer_subform!assesment_subform!cb_asses_36)) Then
.ActiveDocument.FormFields("cb_asses_36").CheckBox.Value = True
End If
If (CStr(Forms!customer_subform!assesment_subform!cb_asses_37)) Then
.ActiveDocument.FormFields("cb_asses_37").CheckBox.Value = True
End If
If (CStr(Forms!customer_subform!assesment_subform!cb_asses_38)) Then
.ActiveDocument.FormFields("cb_asses_38").CheckBox.Value = True
End If
If (CStr(Forms!customer_subform!assesment_subform!cb_asses_39)) Then
.ActiveDocument.FormFields("cb_asses_39").CheckBox.Value = True
End If
If (CStr(Forms!customer_subform!assesment_subform!cb_asses_40)) Then
.ActiveDocument.FormFields("cb_asses_40").CheckBox.Value = True
End If
If (CStr(Forms!customer_subform!assesment_subform!cb_asses_41)) Then
.ActiveDocument.FormFields("cb_asses_41").CheckBox.Value = True
End If
If (CStr(Forms!customer_subform!assesment_subform!cb_asses_42)) Then
.ActiveDocument.FormFields("cb_asses_42").CheckBox.Value = True
End If
If (CStr(Forms!customer_subform!assesment_subform!cb_asses_43)) Then
.ActiveDocument.FormFields("cb_asses_43").CheckBox.Value = True
End If
If (CStr(Forms!customer_subform!assesment_subform!cb_asses_44)) Then
.ActiveDocument.FormFields("cb_asses_44").CheckBox.Value = True
End If
End With
DoEvents
Set MyWord = Nothing
'End If
On Error GoTo Err_Enveloppe_Click

Exit_Enveloppe_Click:
Exit Sub

Err_Enveloppe_Click:
MsgBox Err.Description
 
Yep

My MailMerge works flawlessly! However, if I want to update this database along with new fields in a document, I have to open and edit my code everytime. So if I could have a "for loop" that would start with field number 1 and added 1 until it doesn't find any more fields, it would be perfect. Then if I want to add a field and a bookmark to my document, I just have to match the field names from access and word and I don't have to touch the code. Make Sense?
 
Yeah it makes sense, I'm just not sure if you can do it since you are dealing with fields rather than records. I could be very wrong of course so I'll keep looking for you.

Do you know roughly how many fields you will be adding? Another option would be to add these fields now to your table, form & code, and then add the bookmarks as & when you need them. Not ideal but could save time in the long run. Will let you know if I come up with anything.
 
after68,
I use an Access form to create a Word document and had given up on being able to merge using a subform because I was unable to name the bookmarks past the first entry. I had resolved myself to a huge single form with an embarressing number of table fields. Your code seems to make it possible to merge with a subform. Is your subform field named "txt_asses"? Does it contain up to 90 entries? Could this code be applied to any subform? Thanks
 
This is utterly untested and I'm not sure I have the right format for a subform, but try this integrated into your existing code as appropriate:

Code:
Dim x As Integer

For x = 1 to 89
  .ActiveDocument.Bookmarks("txt_asses_" & x).Select
  .Selection.Text = (CStr(Forms!customer_subform!assesment_subform("txt _asses_" & x) & ""))
Next x
 
Thanks PBaldy,
I'll get out my old form and subform, dust it off and give it a try.
 
Sorry, I didn't pick up on the fact that this was a revival of an old thread, so that answer was more geared towards the original request. If that doesn't help, let me know and I'll try to tweak it for you.

Welcome to the site by the way.
 

Users who are viewing this thread

Back
Top Bottom