Prohibit Down Arrow Scroll in Textbox

W

wrldruler

I have a textbox of a particular size. This size matches the size of
the box on a report. If users write too much text, it will overflow
the report box. So they need to use only the room available in the
textbox.

I have disabled scrollbars on the textbox, as well as disabled Can
Grow and Can Shrink.

But the users are still able to type as much as they want. The textbox
still scrolls to the next line. They can still use the down arrow on
the keyboard to scroll down the textbox.

How can I create a textbox of a fixed hieght, that cannot scroll down
no matter what?

Thanks
 
D

Damon Heron

If the text box is bound to a table, then open the table design view and
limit the characters to whatever fits.
Also you can use the KeyPress event to count the characters (note that the
ct is dimmed in the form module):
Option Compare Database
Option Explicit
Dim ct As Integer

'***********Here is the key press event, using a textbox called my text with
a limit of 30 characters**********
Private Sub my_text_KeyPress(KeyAscii As Integer)
ct = ct + 1
If ct >= 30 Then
MsgBox "This is the end", vbCritical, "Message"
End If
End Sub

This will require you to reset the ct to zero when entering a new record's
textbox.
Damon
 
R

rvanl

If the field is unbound, you still can use the validation Rule option
of the textbox to limit the # of characters as well with the len()
function
R
 
W

wrldruler

I've done character limits before, but it didn't completely solve the
problem. Someone can use line breaks, write only a couple words, but
still exceed the hieght of the box.

For instance:

* The project

* Is going

* Very Well

The above is only 34 characters, but 5 lines, and would likely fill
the box.

So is there a way to count lines instead?

Thanks
 
D

Douglas J. Steele

It takes two characters to represent a new line (Chr(13), which is a
carriage return and Chr(10), which is a line feed). You can determine the
number of lines using:

Len("text to check") - Len(Replace("text to check", Chr(13) & Chr(10),
""))/2

If you've got the text in a variable strText, that would be

Len(strText) - Len(Replace(strText, Chr(13) & Chr(10), ""))/2

If it's in text box Text0 and your code is in the module associated with
that form, it's

Len(Me.Text0) - Len(Replace(Me.Text0, Chr(13) & Chr(10), ""))/2

If your codes not in the module associated with the form, it's

Len(Forms!NameOfForm.Text0) - Len(Replace(Forms!NameOfForm.Text, Chr(13) &
Chr(10), ""))/2
 
D

Damon Heron

This will help strip the string of its crs.....

Private Sub textbox1_Exit(Cancel As Integer)
Dim myStr As String
If Not IsNull(Me.textbox1) Then
myStr = Me.textbox1
Me.textbox1 = Replace(myStr, Chr(13) & Chr(10), " ")
End If
End Sub

Damon
 

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