[Webinar] Streamline your web hosting managementRegister Today

x
  • Status: Solved
  • Priority: Medium
  • Security: Public
  • Views: 268
  • Last Modified:

Input mask

When I want to restrict the input length of a field on a form to 30 characters, I can use :

>CCCCCCCCCCCCCCCCCCCCCCCCCCCCCC

Isn't their a simpler way to do this
It becomes annoying when the field is 100 characters long.

rene
0
rdevriend
Asked:
rdevriend
  • 6
  • 4
  • 3
  • +2
1 Solution
 
HaineseyCommented:
I think you set the length within the table's design (not the form) and if the textbox is linked to that field in the table it limits it automatically.
0
 
njelgerCommented:
True. Use the FieldSize property for a limit on strings. (Text in table design) Standard is 50.

or use this if you need different lengths in different forms:

Private Sub FieldName_BeforeUpdate(Cancel As Integer)
If Len(Me.FieldName) > 30 Then
 MsgBox "too long " & Len(Me.FieldName)
 DoCmd.CancelEvent
End If
End sub

/ j
0
 
rdevriendAuthor Commented:
The field is not linked to a table field, so I cannot use this.
0
The new generation of project management tools

With monday.com’s project management tool, you can see what everyone on your team is working in a single glance. Its intuitive dashboards are customizable, so you can create systems that work for you.

 
shanesuebsahakarnCommented:
In the properties of the text box, set the Validation Rule to:
Len(Form!MyTextBox)<=30

Then set the Validation Text to something appropriate. Change MyTextBox to the name of your text box.
0
 
rdevriendAuthor Commented:
It is a solution, but I don't like it. I would prefer that the user cannot type more characters as the length limits.
0
 
njelgerCommented:
here is some hasty work i did. i think it works but please tidy it up if you use it. good luck.

/ j

Private Sub MyTextBox_KeyPress(KeyAscii As Integer)
Me.Refresh
   If Not IsNull(Me.MyTextBox) Then
    Me.MyTextBox.SelStart = Len(Me.MyTextBox)
    Me.MyTextBox.SelLength = 0
   End If
  If Len(Me.MyTextBox) > 30 Then
   MsgBox "too long " & Len(Me.MyTextBox)
   Me.MyTextBox= Left(Me.MyTextBox, 30)
   Me.MyTextBox.SelStart = 30
   Me.MyTextBox.SelLength = 0
  End If
End Sub
0
 
rdevriendAuthor Commented:
Auw, this has a big impact on the performance. After every keypress, this function is invoked.

Sorry, not a useful solution.
0
 
shanesuebsahakarnCommented:
If you are looking for a property setting that can be changed to give you the behaviour you want - there isn't one.
0
 
njelgerCommented:
well, good luck in your search.

/ j
0
 
moduloCommented:
Dear expert(s),

A request has been made to close this Q in CS:
http://www.experts-exchange.com/Community_Support/Q_20553333.html

Without a response in 72 hrs, a moderator will finalize this question by:

 - Saving this Q as a PAQ and refunding the points to the questionner

When you agree or disagree, please add a comment here.

Thank you.

modulo

Community Support Moderator
Experts Exchange
0
 
shanesuebsahakarnCommented:
I do not agree with this. Several answer was provided that would do what was asked but the questioner felt that they were not sufficient or did not fulfil his exact requirement - we are not responsible for the limitations of the technology. One of the provided workarounds would need to be adopted.
0
 
rdevriendAuthor Commented:
Sorry, but nobody gave the solution I asked for. It were all workarounds. I cannot give points just because of the fact that you gave an answer.  
0
 
shanesuebsahakarnCommented:
I will leave this to modulo to judge.
0
 
rdevriendAuthor Commented:
Yep, modulo, please advise.
0
 
moduloCommented:
Hi rdevriend,

I guess shanesuebsahakarn has a point.
You're asking for a workaround and multiple have been given.

In general a keypress function won't slow the form processing that much that a user will notice, but as you reject that option, the comment of shanesuebsahakarn "there isn't one" would be the "answer".

modulo

Community Support Moderator
Experts Exchange
0
 
rdevriendAuthor Commented:
I do not agree with modulo, I never asked for a workaround, but I am no longer going to argue about just 50 points. If this is really the view from Modulo, I must accept  Njelger's first answer.
0

Featured Post

The new generation of project management tools

With monday.com’s project management tool, you can see what everyone on your team is working in a single glance. Its intuitive dashboards are customizable, so you can create systems that work for you.

  • 6
  • 4
  • 3
  • +2
Tackle projects and never again get stuck behind a technical roadblock.
Join Now