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 SkipVought on being selected by the Tek-Tips community for having the most helpful posts in the forums last week. Way to Go!

Data access page Limit Text box field size to 255

Status
Not open for further replies.

rhinomac

Programmer
Jan 24, 2003
34
0
0
US
Hello,
I am trying to limit the amount of characters that can be entered into a text box on a data access page in ms access. Currently it will allow the user to enter as many characters as they want then it truncates it to 255 when it saves it.

I would like to limit it to 255 so it doesnt allow them to enter more than 255 as there typing. Now it just keeps droping down to a new line every time it reached the end of the box.

I am aware that if you set the field to memo instead of text there is 64,000 character limit.

Thanks, in advance
-Rhino
I would like to refrain from that tough. - Dont want to bog down the database.
 
Paste the following code into your form's Code Module:

Code:
Private Declare Function SendMessageA& Lib "user32" (ByVal hwnd&, ByVal wMsg&, ByVal wParam&, lParam As Any)

Private Declare Function GetFocus& Lib "user32" ()

Private Const EM_LIMITTEXT = &HC5


Private Function TextLimit()
        Call SendMessage(GetFocus(), EM_LIMITTEXT, 255, ByVal 0&)
End Sub

Next, select the TextBox you wish to limit and set its OnChange Property to: [tt]=TextLimit()[/tt]

Finally, save the changes to the form and try it out.
 
Will this work for a data access page.
I do not see the on change property for the text box.
 
Whoops, my misunderstanding. I was thinking of an Access Form, not a data access page.

I can tell you the HTML structure for the form input:

Code:
<INPUT TYPE=TEXT NAME="MyTextBox" MAXLENGTH=255><BR>
 
Ok, I figured out where to put the on change property is.
I went into the script editor and double clicked on "on change" for the field and inserted the code.

THe only problem I'm having is where to paste the top part of the code. You say "Paste the following code into your form's Code Module:"
Where on the form do you place it. Do you just insert it or do you need to create a script block.

THanks again,
Rhino


 
Status
Not open for further replies.

Part and Inventory Search

Sponsor

Back
Top