Results 1 to 9 of 9
  1. #1
    Join Date
    Aug 2005
    Posts
    196

    Unanswered: Number of characters in a text box

    Is there any way you can say for example set a text box to have a minumum and maximum length of 5 characters? I've looked in the property box but nothing obvious seems to be there, cheers.

  2. #2
    Join Date
    Sep 2003
    Location
    MI
    Posts
    3,713
    Quote Originally Posted by Fuerteventura
    Is there any way you can say for example set a text box to have a minumum and maximum length of 5 characters? I've looked in the property box but nothing obvious seems to be there, cheers.
    Only thru event coding ... Try: BeforeUpdate, AfterUpdate, LostFocus events
    Back to Access ... ADO is not the way to go for speed ...

  3. #3
    Join Date
    Aug 2005
    Posts
    196
    Many thanks for your reply - Something like this I presume:

    Code:
    If Len(txtBox.Text) < 5 Then
    
    (code in here)
    
    End if
    Any clues as to how I prevent the user from entering another character?
    Cheers.

  4. #4
    Join Date
    May 2004
    Posts
    65

    AfterUpdate Event

    On the afterupdate event do the following:

    If len(yourstringname) < 3 (or whatever number you want) then
    'do something here
    end if

  5. #5
    Join Date
    Aug 2005
    Posts
    196
    this is where I'm at now:

    Code:
    Private Sub TextBox_Change()
    
    Dim MoreThanFive As Integer
    Let MoreThanFive = 0
        If Len(TextBox.Text) > 5 Then
            MoreThanFive = Len(TextBox) - 5
            Right(TextBox.Text, MoreThanFive).Delete
           
        End If
    
    End Sub
    It's telling me an object is required on the delete line - any ideas anyone? Cheers.

  6. #6
    Join Date
    Nov 2004
    Location
    out on a limb
    Posts
    13,692
    Provided Answers: 59
    a better solution is probably to place some validationm code in the forms before update event.

    in essnece what you are looking for is something similar to

    dim intStrLen as integer
    intStrLen=len(<mycontrolname>)
    if intStrLen<>5 then
    'do your error processing
    cancel=true 'forces the update to be abandoned
    endif

    HTH

    BTW if you need more info on what events are and how they are used try the help system. if you want to work out what event to use I'd suggest that you place soem code in the each control with a suitable message to work out when an event fires.

  7. #7
    Join Date
    May 2004
    Posts
    65

    just use left

    fieldname = left(fieldname,5)
    'that way you dont need all the other stuff. If the text field is less than five then it is left as it was.

  8. #8
    Join Date
    Nov 2004
    Location
    out on a limb
    Posts
    13,692
    Provided Answers: 59
    fieldname = left(fieldname,5)
    ...chops the field name to be the first 5 characters , which isn't the same as resets to the original value, if you want to do that then you many be able to use the .oldvalue property

    if the requirement is to force users to put in 5 and only 5 characters then Id' suggest keeping themm in the record untill the beofre update event lets them save the recod. however if you go down this route then make sure you tell your users why the record can't be updated, otherwise the support help line will go red hot with confused (well justifiably confused) users

  9. #9
    Join Date
    Aug 2005
    Posts
    196
    Thank you both very much for that, cheers.

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts
  •