?
Solved

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

Posted on 2015-02-05
4
Medium Priority
?
232 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
[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
  • 2
4 Comments
 
LVL 51

Accepted Solution

by:
Gustav Brock earned 1000 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 58

Assisted Solution

by:Jim Dettman (Microsoft MVP/ EE MVE)
Jim Dettman (Microsoft MVP/ EE MVE) earned 1000 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 51

Expert Comment

by:Gustav Brock
ID: 40590915
You are welcome!

/gustav
0

Featured Post

VIDEO: THE CONCERTO CLOUD FOR HEALTHCARE

Modern healthcare requires a modern cloud. View this brief video to understand how the Concerto Cloud for Healthcare can help your organization.

Question has a verified solution.

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

This article describes two methods for creating a combo box that can be used to add new items to the row source -- one for simple lookup tables, and one for a more complex row source where the new item needs data for several fields.
Microsoft Access is a place to store data within tables and represent this stored data using multiple database objects such as in form of macros, forms, reports, etc. After a MS Access database is created there is need to improve the performance and…
In Microsoft Access, learn different ways of passing a string value within a string argument. Also learn what a “Type Mis-match” error is about.
With Secure Portal Encryption, the recipient is sent a link to their email address directing them to the email laundry delivery page. From there, the recipient will be required to enter a user name and password to enter the page. Once the recipient …
Suggested Courses

777 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