From Form to Word 256 Characters

G

Guest

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 in various table. The data
changes etc and via a form we export it back for various reasons.

I use the following

Code:

Private Sub ExportPDForm_Click()
Dim wrdApp As Object

Set wrdApp = CreateObject("Word.Application")
Set wrdDoc = wrdApp.Documents.Add(CurrentProject.Path & "\Personal Data
Form.dot")


With wrdDoc

'*****Personnell Info Export ******************

.FormFields("Title").Result = Me.Form.Title
.FormFields("FirstName").Result = Me.Form.[First Name]
.FormFields("Initials").Result = Me.Form.Initials
.FormFields("Surname").Result = Me.Form.Surname
.FormFields("Middlename").Result = Me.Form.[Middle Name]
.FormFields("KnownAs").Result = Me.Form.KnownAs

.FormFields("AddInfo1").Range = 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]

+ 150 extra
--------------------------------------------------------------------------------


Due to the fact that some of the data in my DB is in a memo field ( 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 String
Str1 = (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.Unprotect
FmFld.Range.Fields(1).Result.Text = Str1
ActiveDocument.Protect Type:=wdAllowOnlyFormFields, NoReset:=True

Or if you're referring to the formfield by name:

ActiveDocument.Unprotect
ActiveDocument.Bookmarks("Text1").Range.Fields(1).Result.Text = Str1
ActiveDocument.Protect Type:=wdAllowOnlyFormFields, NoReset:=True

---------------
I was informed to change the REsult to Range

.FormFields("AddInfo1").Result = Me.Form.[Additional Information1]
.FormFields("AddInfo1").Range = Me.Form.[Add Information1]

If i do this, i do net not get the String to Long Error, but Document
proctected cant continue.

I unportected the document just for testing purpose and filled in all fields
perfectly where it has been set to "Result" and still keeps the bookmark
meaning I can re-protect the document and my bookmarks would be there for
later use.

however with the "Range". it fills the document perfectly, but it
completely replaces the bookmark. Meaning it is lost for later.

Now i have tried various ways to try and change my current code to make use
of the above code. And not winning.

Is there a possible way, to insert records into a document where the
Characters are more than 256 and not loose the current bookmark.

Any advise would greatly apreciated.

Kind Regards
Sn
 
G

Guest

Copied this to Export / Import

SN said:
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 in various table. The data
changes etc and via a form we export it back for various reasons.

I use the following

Code:

Private Sub ExportPDForm_Click()
Dim wrdApp As Object

Set wrdApp = CreateObject("Word.Application")
Set wrdDoc = wrdApp.Documents.Add(CurrentProject.Path & "\Personal Data
Form.dot")


With wrdDoc

'*****Personnell Info Export ******************

.FormFields("Title").Result = Me.Form.Title
.FormFields("FirstName").Result = Me.Form.[First Name]
.FormFields("Initials").Result = Me.Form.Initials
.FormFields("Surname").Result = Me.Form.Surname
.FormFields("Middlename").Result = Me.Form.[Middle Name]
.FormFields("KnownAs").Result = Me.Form.KnownAs

.FormFields("AddInfo1").Range = 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]

+ 150 extra
--------------------------------------------------------------------------------


Due to the fact that some of the data in my DB is in a memo field ( 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 String
Str1 = (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.Unprotect
FmFld.Range.Fields(1).Result.Text = Str1
ActiveDocument.Protect Type:=wdAllowOnlyFormFields, NoReset:=True

Or if you're referring to the formfield by name:

ActiveDocument.Unprotect
ActiveDocument.Bookmarks("Text1").Range.Fields(1).Result.Text = Str1
ActiveDocument.Protect Type:=wdAllowOnlyFormFields, NoReset:=True

---------------
I was informed to change the REsult to Range

.FormFields("AddInfo1").Result = Me.Form.[Additional Information1]
.FormFields("AddInfo1").Range = Me.Form.[Add Information1]

If i do this, i do net not get the String to Long Error, but Document
proctected cant continue.

I unportected the document just for testing purpose and filled in all fields
perfectly where it has been set to "Result" and still keeps the bookmark
meaning I can re-protect the document and my bookmarks would be there for
later use.

however with the "Range". it fills the document perfectly, but it
completely replaces the bookmark. Meaning it is lost for later.

Now i have tried various ways to try and change my current code to make use
of the above code. And not winning.

Is there a possible way, to insert records into a document where the
Characters are more than 256 and not loose the current bookmark.

Any advise would greatly apreciated.

Kind Regards
Sn
 

Ask a Question

Want to reply to this thread or ask your own question?

You'll need to choose a username for the site, which only take a couple of moments. After that, you can post your question and our members will help you out.

Ask a Question

Top