Limit the No. of characters in an unbound textbox?

MsLady

Traumatized by Access
Local time
Today, 03:36
Joined
Jun 14, 2004
Messages
438
Is there a way to limit the number of characters that can be entered into an unbound textbox on my form?

I have a search textbox, where a jobId is entered and button is clicked to search. The numbers are generally 8-digit. I just noticed one of my users trying to enter 9489858939349839434 :eek: ohh lawd. Please help me stop these people before they break my db...
 
The Change event fires every keystroke and Len(Me.YourTextBox.Text) will tell you how many characters have been entered so far. Post back if you need more clues M'Lady. ;)
 
RuralGuy said:
The Change event fires every keystroke and Len(Me.YourTextBox.Text) will tell you how many characters have been entered so far. Post back if you need more clues M'Lady. ;)

Thanks boss! :)
Code:
Private Sub txtjobId_Change()
If Len(Me.txtjobId.Text) <= 8 Then
Else
MsgBox "Only 8-digits allowed stupid!"
End If
End Sub
Here's what i have, but this does not stop them, i just want it to stop allowing more text instead of my msgbox. how do i stop text..like anykey stokes after that should have no effect :o
 
I’m a little surprised at the time difference I see so will put it down to daylight saving on the server. :D

Another approach would be to do the search from the On Change event of the text box. Initially no records are found but then when they type 9 they get all JobID’s starting with 9, then they type 4, 8 and 9 and get all records starting with 9489. You don’t have to show the records but maybe simply display the search record count and stop at 0 records by not allowing further key entry except the backspace key.

Another simpler approach is to give them a JobID’s combo box set to limit to list.

Either way the idea is to disallow users typing junk over known variable length strings.
(You’re JobID is a string and not a number I hope.)

Hope that makes some sense.

Regards,
Chris.
 
Thanks Chris makes alot of sense, but i like the approach of simply blocking more entries after 8characters :)
 
MsLady.

Well, part of your question was ‘The numbers are generally 8-digit.’

Therefore a question arises in my mind, why accept a fixed length string search criteria if the search is to be done on a variable length string field?

To find a unique record we need an exact match.

Regards,
Chris.
 
ChrisO said:
MsLady.

Well, part of your question was ‘The numbers are generally 8-digit.’

Therefore a question arises in my mind, why accept a fixed length string search criteria if the search is to be done on a variable length string field?

To find a unique record we need an exact match.

Regards,
Chris.
the characters would either be 7 or 8. i.e.
mmyy0001 (8060001 - august entries and 10060001 - oct/nov/dec entries).

My jobid wasn't allowing the leading zero as in 08060001, so here's what im settling for and i am happy with it! :D
 
I know this may sound simple.......... But why not simply put this.... "999999999;;_" in the input mask of the unbound textbox? (without the quotes)
 
CEH said:
I know this may sound simple.......... But why not simply put this.... "999999999;;_" in the input mask of the unbound textbox? (without the quotes)
Hmn...thanks CEH, I had seen this someone and read that the "_" causes problem. But why not? I used yours. It works, haven't had a problems.

wheew..Thanks :D
 
I think what they may have been refering to was using the character "_" in code. The "999999999;;_" came straight from the input box wizard of Access..... Sooooo..... I don't think you'll have a problem. If so blame Microsoft :)
 
How about using the Left function in the OnChange event to limit it to the first left 8 characters?
 
Quick fix to this problem

I came across this forum trying to solve the same problem, and the above comments were very helpful. Here is a shorter solution for anyone interested, that simply stops a user from entering more than 8 characters. This is the On_Change event of the textbox whose length I want to limit.

Code:
Private Sub txtDescription_Change()

    Dim strCharCount As String
    
    strCharCount = Len(Me.txtDescription.Text)
    
    If strCharCount >= 8 Then
        Me.txtDescription = Left(Me.txtDescription.Text, 8)
        Me.txtDescription.SelStart = 8
    End If

End Sub
 

Users who are viewing this thread

Back
Top Bottom