?
Solved

Input mask

Posted on 2003-03-12
16
Medium Priority
?
257 Views
Last Modified: 2006-11-17
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
Comment
Question by:rdevriend
[X]
Welcome to Experts Exchange

Add your voice to the tech community where 5M+ people just like you are talking about what matters.

  • Help others & share knowledge
  • Earn cash & points
  • Learn & ask questions
  • 6
  • 4
  • 3
  • +2
16 Comments
 

Expert Comment

by:Hainesey
ID: 8118446
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
 
LVL 1

Accepted Solution

by:
njelger earned 100 total points
ID: 8118589
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
 

Author Comment

by:rdevriend
ID: 8118727
The field is not linked to a table field, so I cannot use this.
0
What Is Blockchain Technology?

Blockchain is a technology that underpins the success of Bitcoin and other digital currencies, but it has uses far beyond finance. Learn how blockchain works and why it is proving disruptive to other areas of IT.

 
LVL 41

Expert Comment

by:shanesuebsahakarn
ID: 8118922
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
 

Author Comment

by:rdevriend
ID: 8119148
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
 
LVL 1

Expert Comment

by:njelger
ID: 8119334
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
 

Author Comment

by:rdevriend
ID: 8119414
Auw, this has a big impact on the performance. After every keypress, this function is invoked.

Sorry, not a useful solution.
0
 
LVL 41

Expert Comment

by:shanesuebsahakarn
ID: 8119629
If you are looking for a property setting that can be changed to give you the behaviour you want - there isn't one.
0
 
LVL 1

Expert Comment

by:njelger
ID: 8119682
well, good luck in your search.

/ j
0
 

Expert Comment

by:modulo
ID: 8152127
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
 
LVL 41

Expert Comment

by:shanesuebsahakarn
ID: 8152410
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
 

Author Comment

by:rdevriend
ID: 8152482
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
 
LVL 41

Expert Comment

by:shanesuebsahakarn
ID: 8152566
I will leave this to modulo to judge.
0
 

Author Comment

by:rdevriend
ID: 8152730
Yep, modulo, please advise.
0
 

Expert Comment

by:modulo
ID: 8159468
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
 

Author Comment

by:rdevriend
ID: 8159543
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

How Blockchain Is Impacting Every Industry

Blockchain expert Alex Tapscott talks to Acronis VP Frank Jablonski about this revolutionary technology and how it's making inroads into other industries and facets of everyday life.

Question has a verified solution.

If you are experiencing a similar issue, please ask a related question

As tax season makes its return, so does the increase in cyber crime and tax refund phishing that comes with it
You need to know the location of the Office templates folder, so that when you create new templates, they are saved to that location, and thus are available for selection when creating new documents.  The steps to find the Templates folder path are …
In Microsoft Access, learn the trick to repeating sub-report headings at the top of each page. The problem with sub-reports and headings: Add a dummy group to the sub report using the expression =1: Set the “Repeat Section” property of the dummy…
Have you created a query with information for a calendar? ... and then, abra-cadabra, the calendar is done?! I am going to show you how to make that happen. Visualize your data!  ... really see it To use the code to create a calendar from a q…
Suggested Courses

762 members asked questions and received personalized solutions in the past 7 days.

Join the community of 500,000 technology professionals and ask your questions.

Join & Ask a Question