Solved

Use input mask and/or validation to exclude "space" from input in table.

Posted on 2015-02-05
4
200 Views
Last Modified: 2015-02-05
I have a table with a file number [File].
It should not have more than 6 characters consisting of four digits plus an optional further 2 digits or letters, BUT no spaces or other punctuation.
I am using Access 2010.
The input mask that I have at present is 0000aa.
What happens is that if the user enters for instance 1234"space""space", the result ignores the space, but if he enters 1234"space"6, then the space is not ignores and the [File] is 1234 6.
I want the database to refuse to accept any space in the input.
I attach my very simple database. It should open on the table [Files]. There is also a [Form Files] where the length of each [File] is calculated.
Will someone please help me with this. I have spent hours.
Test1.accdb
0
Comment
Question by:Fritz Paul
  • 2
4 Comments
 
LVL 49

Accepted Solution

by:
Gustav Brock earned 250 total points
ID: 40590737
As the placeholders are optional, they cannot be required, neither single or both.

You will have to add code in the BeforeUpdate event to check for Spaces and Cancel if so:

    Cancel = CBool(InStr(Me!File.Value, " "))

Using a key stroke filter will not do as the user can copy/paste.

/gustav
0
 
LVL 57

Assisted Solution

by:Jim Dettman (Microsoft MVP/ EE MVE)
Jim Dettman (Microsoft MVP/ EE MVE) earned 250 total points
ID: 40590749
Fritiz,

<<I want the database to refuse to accept any space in the input.>>

When a input mask won't do the job, you have two basic options:

1. Check each character as the user types.

2. Check the entire entry before the control is updated.

The first is done in the OnChange event of the control.  You can use the .Text property to get the value of the buffer, then look at the last character.

The second is done in the BeforeUpdate event of the control.  You can either loop through each character and check for bad punctuation using Instr() or you can check the entire entry at once using Replace() and doing that  for each possible illegal character.

The first method is more efficient when you have a large range of illegal characters possible.

Jim.
0
 

Author Closing Comment

by:Fritz Paul
ID: 40590911
Thanks, Both answers were informative and helped me solve the problem.
0
 
LVL 49

Expert Comment

by:Gustav Brock
ID: 40590915
You are welcome!

/gustav
0

Featured Post

Is Your Active Directory as Secure as You Think?

More than 75% of all records are compromised because of the loss or theft of a privileged credential. Experts have been exploring Active Directory infrastructure to identify key threats and establish best practices for keeping data safe. Attend this month’s webinar to learn more.

Question has a verified solution.

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

Suggested Solutions

Title # Comments Views Activity
Field behavior for "locked" form 12 29
sort Time by AM and PM in query 2 20
Storing Combo Box Selection in Table 12 45
access 7 26
QuickBooks® has a great invoice interface that we were happy with for a while but that changed in 2001 through no fault of Intuit®. Our industry's unit names are dictated by RUS: the Rural Utilities Services division of USDA. Contracts contain un…
In a multiple monitor setup, if you don't want to use AutoCenter to position your popup forms, you have a problem: where will they appear?  Sometimes you may have an additional problem: where the devil did they go?  If you last had a popup form open…
As developers, we are not limited to the functions provided by the VBA language. In addition, we can call the functions that are part of the Windows operating system. These functions are part of the Windows API (Application Programming Interface). U…
Familiarize people with the process of utilizing SQL Server stored procedures from within Microsoft Access. Microsoft Access is a very powerful client/server development tool. One of the SQL Server objects that you can interact with from within Micr…

867 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

Need Help in Real-Time?

Connect with top rated Experts

15 Experts available now in Live!

Get 1:1 Help Now