Good Day.
I am currently via Form send data to a word template..
I have about 150 bookmarks in a word document which was previously imported via a simular document. and appended into my DB. The data changes etc we export it back for various reasons.
I use the following
Code:
--------------------------------------------------------------------------------
Private Sub ExportPDForm_Click()
Dim wrdApp As Object
Dim wrdDoc As Object
Set wrdApp = CreateObject("Word.Application")
Set wrdDoc = wrdApp.Documents.Add(CurrentProject.Path & "\Personal Data Form.dot")
With wrdDoc
.FormFields("Title").Result = Me.Form.Title
.FormFields("FirstName").Result = Me.Form.[First Name]
.FormFields("AddInfo1").Result = Me.Form.[Add Information1]
.FormFields("AddInfo2").Result = Me.Form.[Additional Information2]
.FormFields("SummCivSkills1").Result = Me.Form.[Summary Civ Skills1]
.FormFields("SummCivSkills2").Result = Me.Form.[Summary Civ Skills2]
.FormFields("SummMilSkills1").Result = Me.Form.[Summary Mil Skills1]
.FormFields("SummMilSkills2").Result = Me.Form.[Summary Mil Skills2]
.FormFields("SummCompSkills1").Result = Me.Form.[Computer Skills1]
.FormFields("SummCompSkills2").Result = Me.Form.[Computer Skills2] etc etch... + 150 records
End With
wrdDoc.SaveAs gcPDExportPath & ID
wrdApp.Visible = TrueEnd Sub
--------------------------------------------------------------------------------
Due to the fact that some of the data in my DB is in a memo field ( The fields listed in blue ) Consist of more than 256 caracters i get a string to long error.
I then search the internet and found the following from a MPV website on how to by pass it.
Code:
--------------------------------------------------------------------------------
If you use:
Dim FmFld As FormField,
Str1 As StringStr1 = (a long string > 256 characters)
Set FmFld = ActiveDocument.FormFields(1)
FmFld.Result = Str1
You get an error: “String too long” (a ridiculous “design” feature, given that you can do it manually without problems!).Same if you use:
ActiveDocument.Formfields("Text1").Result = Str1
You can get round this by using:
ActiveDocument.UnprotectFmFld.Range.Fields(1)
.Result.Text = Str1ActiveDocument.Protect Type:=wdAllowOnlyFormFields, NoReset:=True
Or if you're referring to the formfield by name:ActiveDocument.UnprotectActiveDocument.Bookma rks("Text1").Range.Fields(1).Result.Text = Str1ActiveDocument.Protect Type:=wdAllowOnlyFormFields, NoReset:=True
--------------------------------------------------------------------------------
Now i have tried various ways to try and change my current code to make use of the above code. But Removed the to unprotect Document/ protect doc due to the fact that it would replace my bookmarks for later use.
I was hoping someone could perhaps assist in how i could amend the above mentioned. To allow the insert of records more than 256 caracters. Since the ways i have tried still gives me my String To long Error. Any advise would be apreciated.
Kind Regards
Sn