UtterAccess.com
X   Site Message
(Message will auto close in 2 seconds)

Welcome Guest ( Log In | Register )

 
Reply to this topicStart new topic
> 255 character max limit on formfields problem    
 
   
Dionysus
post Mar 22 2007, 06:34 AM
Post #1

UtterAccess Addict
Posts: 137
From: Newcastle, UK



Morning all,

I have setup a lot of templates each with their own various logos for different partners and what I want to do is use each template as a base for different letters, rather than create them all again just for a new letter type. So from the database it looks up in a table I setup for the type of letter to use, opens the relevant word template and populates the 'BodyText' formfield with the body of the letter.

The problem is for some reason seems to be a limit on the size of the text a formfield can hold (255 max) and I need to populate much more than this. How can I get around this?

I recieve the following error:
Run-time error '4609': "String too long"

I have looked at the following link but I do not understand it:
http://support.microsoft.com/kb/163192

Can anyone please help?
Go to the top of the page
 
+
buchj
post Mar 22 2007, 06:54 AM
Post #2

UtterAccess Member
Posts: 40
From: Barcelona, Spain



Dionysus,

Yes, as far as I know this is true, a formfield text can only have 255 characters.

The workaround proposed by MS in the article is, as I understand, very stupid. Here's what it does:

It fills the Formfield with 4 "*" characters:
CODE
ActiveDocument.FormFields("text1").Result = "****"


It positions the cursor on the 2nd "*" in the formfield:
CODE
Selection.GoTo What:=wdGoToBookmark, Name:="Text1"
Selection.Collapse
Selection.MoveRight wdCharacter, 1


It then fills the formfield with 256 "W" characters:
CODE
Selection.TypeText (String(256, "W"))


Finally, it removes all the "*" characters:
CODE
Selection.GoTo what:=wdGoToBookmark, Name:="Text1"
With Selection.Find
.Execute findtext:="*", replacewith:="", replace:=wdReplaceAll
End With


I don't also see why is this working, but if MS say it does...

Hope it helps!

Jordi.
Go to the top of the page
 
+
RAZMaddaz
post Mar 22 2007, 07:22 AM
Post #3

UtterAccess VIP
Posts: 6,171
From: Bethesda, MD USA



Have you tried changing the Data Type from "Text" to "Memo?" This way you won't be limitted to the amount of characters you can enter for the field.
Go to the top of the page
 
+
Dionysus
post Mar 22 2007, 07:35 AM
Post #4

UtterAccess Addict
Posts: 137
From: Newcastle, UK



Thanks for the breakdown, it has really helped.

I replaced:
Selection.TypeText (String(256, "W"))

With:
Selection.TypeText strBodyText

However, I'm getting a very weird error now:

Run-Time Error '462':
The Remote server machine does not exist or is unavailable

If I click on 'End' and then immediatly try it again it actually works, but...

Any idea how to get around this error?
Go to the top of the page
 
+
HiTechCoach
post Mar 22 2007, 08:08 AM
Post #5

UtterAccess VIP
Posts: 18,396
From: Oklahoma City, Oklahoma



RAZMaddaz ,

I think that problem is that the data type in Access is a memo field but the form field in Word is limited to 255 characters and will not accept all the data from the Access memo field.
Go to the top of the page
 
+
zocker
post Mar 22 2007, 08:15 AM
Post #6

Utterly Eccentric and Moderator
Posts: 3,667
From: Bristol / Ipswich / Spain



Its a Word form field so apparently will not accept more than 255 chars. Can you use 2 (or more) form fields? If so you could set up a query to supply the results, a query field could be 'First255' and 'Second255' based on your memo table field.

HTH

Z
Go to the top of the page
 
+
RAZMaddaz
post Mar 22 2007, 08:16 AM
Post #7

UtterAccess VIP
Posts: 6,171
From: Bethesda, MD USA



Gotcha!!! Sorry, I am on my first cup of coffee and I some how didn't read the Word part of the original problem. If I think of something else I'll let everyone know, otherwise I will shut-up.
Go to the top of the page
 
+
RAZMaddaz
post Mar 22 2007, 08:52 AM
Post #8

UtterAccess VIP
Posts: 6,171
From: Bethesda, MD USA



Have you tried basing the templates on a query instead? In the query you can have something like a Left(string,256) and a Mid(string, start, length) ? Just an idea.
Go to the top of the page
 
+
Dionysus
post Mar 22 2007, 09:18 AM
Post #9

UtterAccess Addict
Posts: 137
From: Newcastle, UK



Thanks, but that would only work assuming the remaining text (mid) was less than 265 otherwise you'll just hit the same problem.

I did say that I kind of got this working, but my main problem now is runtime error 462 - The Remote server machine does not exist or is unavailable. When I run the code it works, then doesn't, then does, then doesn't... you get the idea.

I think something behind the scenes is getting stuck and not resetting within Access, because after it works if I close the database, re-open and try it again it works, but if I simply try it again without closing it thats when I get the error.

I've no idea where to start looking though... please help.
Go to the top of the page
 
+
buchj
post Mar 22 2007, 09:30 AM
Post #10

UtterAccess Member
Posts: 40
From: Barcelona, Spain



Are you saving and closing correctly your Word file every time you run the code?

I mean, if you don't save & close the file at the end of your code, the second time it runs it may be using again the same file, where the formfield is already populated, this failing.

Just a theory...

Jordi
Go to the top of the page
 
+
Dionysus
post Mar 22 2007, 10:11 AM
Post #11

UtterAccess Addict
Posts: 137
From: Newcastle, UK



I see this might cause a problem. The users that use this template may not need to save the document, as it may only need to be printed out and sent in the post.

It maybe worth noting that before I added this extra formfield for the body of the letter, it was working fine (anyone was able to close the template without saving with no problems).

I will test it now though just incase it is what you have suggusted and will post back the results.
Go to the top of the page
 
+
Dionysus
post Mar 22 2007, 10:44 AM
Post #12

UtterAccess Addict
Posts: 137
From: Newcastle, UK



The users need the option to not save the document, so I cant force a save really.

I did a lot more digging around and also found this link:
http://support.microsoft.com/kb/189618/en-us/

This pointed me in the direction that aomewhere in my code the Word Object was not being referenced explicitly.
So, I tried adding 'objWord.' before all the relevant bits of code and now it works! Below is the old code:

Selection.GoTo What:=wdGoToBookmark, Name:="Text1"
Selection.Collapse
Selection.MoveRight wdCharacter, 1
Selection.TypeText strBodyText
Selection.GoTo what:=wdGoToBookmark, Name:="Text1"
With Selection.Find

Here is the code that works:

objWord.Selection.GoTo What:=wdGoToBookmark, Name:="Text1"
objWord.Selection.Collapse
objWord.Selection.MoveRight wdCharacter, 1
objWord.Selection.TypeText strBodyText
objWord.Selection.GoTo what:=wdGoToBookmark, Name:="Text1"
With objWord.Selection.Find

Hope that helps someone else too, it had my head in bits.
Many many thanks to all you who replied with suggestions and advice, without it I would not have found a solution.
Go to the top of the page
 
+

Thank you for your support! Reply to this topicStart new topic

Jump To Forum:
 



RSS Go to Top  ·  Lo-Fi Version Time is now: 24th May 2013 - 06:48 PM

Tag cloud: