Tek-Tips is the largest IT community on the Internet today!

Members share and learn making Tek-Tips Forums the best source of peer-reviewed technical information on the Internet!

  • Congratulations IamaSherpa on being selected by the Tek-Tips community for having the most helpful posts in the forums last week. Way to Go!

Help with combining fields to string together one statement. 1

Status
Not open for further replies.

mrmetal

Technical User
Jul 8, 2005
16
US
I am a novice access programmer and am currently working on my first project. My knowledge of VBA is very limited, but I am trying to learn. I've searched in many books and in different forums across the net for the answer to this one, but can't find it anywhere.

I've made a wizard-type application that contains five different pages(forms). In each, the user answers a single question with a phrase. At the end of the wizard, I want the user to be able to click 'finish' and have Access combine their answers to arrive to a single statement. I knew this would result in a long string, but apparently it is too long because I get a run-time error message that says:

"Run-time error 2221: Text is too long to be edited."

Below is the code that I've written for this:

Private Sub Form_Current()
Dim strObjective As String

FullObjective.SetFocus
strObjective = [Condition] & ", " & [Audience] & " will " & [Behavior] & " " & [Content] & " " & [Degree] & "."
FullObjective.Text = strObjective

End Sub

So, after a long-winded explanation, let me get to my questions:
1) Can a string have more that 255 characters?
2) If so, how do I do it?
3) Is there any on-line help for these run-time errors like there is with VBA?

mrmetal
 
A string can have more than 255 char., but an access Text table data-type can't. A memo data type can have up to 64K, but you should avoid the Memo data type. I think a string variable can have 32K but I'm not sure.

It looks like the table has these fields:
Condition
Audience
Behavior
Content
Degree
FullObjective

FullObjective is really a 'redundant' field--it seems to be basically just the concatenation of the rest of the fields listed. If this is so, then you don't need FullObjective stored in the table. If you need to display it, you can have a textbox that is 'Unbound', meaning you just blank out the ControlSOurce property. You could name it 'txtFullObjective'.

Then create a function within the form module like so:
Code:
Function GetFullObjective() as string
GetFullObjective = me!Condition & ", " & me!Audience & " will " & me!Behavior & " " & me!Content & " " & me!Degree & "."
end function
Then instead of leaving the textbox unbound, put the following in the ControlSource:
=GetFullObjective()
This will automatically keep the field updated as the records are browsed in the form. To keep it updated as each field has data entered, put the following code in the AfterUpdate Event of each field:
Me!txtFullObjective.ReQuery
--Jim
 
Thanks for the thoughtful response! That did it; I needed to change the settings to a memo. I'm not too worried about size, since I'm only designing this for my personal use.

Again, thanks for writing a clear response - one that a novice programmer can follow.

- Ed

 
Status
Not open for further replies.

Part and Inventory Search

Sponsor

Back
Top