CumbrianCanary
Registered User.
- Local time
- Today, 16:13
- Joined
- Sep 13, 2004
- Messages
- 22
I am having some problems exporting data to word from a form. I have used the search feature but can't find anything that helps me out. The form contains a large number of fields and also 3 subforms. All the data needs to be printed and as there are table requiring landscape orientation I have opted to use a Word document with bookmarks.
All worked well until a user wanted some more fields added. The basic code I was using became too big and brought up an error message. So I looked at ways of reducing the repetitive parts of the code. I have tried to do a loop function with changing numbers at the end of each field that should be changed. It seems that Word is really looking for the absolute string name given e.g. strTexta rather than “Texta1” which is what I want it to look for. Could anyone help me with this please?
Many thanks,
CC
All worked well until a user wanted some more fields added. The basic code I was using became too big and brought up an error message. So I looked at ways of reducing the repetitive parts of the code. I have tried to do a loop function with changing numbers at the end of each field that should be changed. It seems that Word is really looking for the absolute string name given e.g. strTexta rather than “Texta1” which is what I want it to look for. Could anyone help me with this please?
Code:
For I = 1 To 12
strTexta = "Texta" & I
strTextb = "Textb" & I
strTextc = "Textc" & I
strTextd = "Textd" & I
strTexte = "Texte" & I
strTextf = "Textf" & I
strTextg = "Textg" & I
strTexth = "Texth" & I
strTexti = "Texti" & I
strTextj = "Textj" & I
strTextk = "Textk" & I
strTextl = "Textl" & I
strTextm = "Textm" & I
strTextn = "Textn" & I
'Data from Subform frmSubForm1
.ActiveDocument.Bookmarks(strTexta).Select
.Selection.Text = (CStr(Forms![frmMain]![frmSubForm1]!strTexth))
.ActiveDocument.Bookmarks(strTextb).Select
.Selection.Text = (CStr(Forms![frmMain]![frmSubForm1]!strTexti))
.ActiveDocument.Bookmarks(strTextc).Select
.Selection.Text = strtemp & (CStr(Forms![frmMain]![frmSubForm1]! strTextj))
.ActiveDocument.Bookmarks(strTextd).Select
.Selection.Text = (CStr(Forms![frmMain]![frmSubForm1]!strTextk))
.ActiveDocument.Bookmarks(strTexte).Select
.Selection.Text = (CStr(Forms![frmMain]![frmSubForm1]!strTextl))
.ActiveDocument.Bookmarks(strTextf).Select
.Selection.Text = (CStr(Forms![frmMain]![frmSubForm1]!strTextm))
.ActiveDocument.Bookmarks(strTextg).Select
.Selection.Text = (CStr(Forms![frmMain]![frmSubForm1]!strTextn))
Next I
Many thanks,
CC