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
Solved

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

Posted on 2015-02-05
4
212 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

Free Tool: Subnet Calculator

The subnet calculator helps you design networks by taking an IP address and network mask and returning information such as network, broadcast address, and host range.

One of a set of tools we're offering as a way of saying thank you for being a part of the community.

Question has a verified solution.

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

I originally created this report in Crystal Reports 2008 where there is an option to underlay sections. I initially came across the problem in Access Reports where I was unable to run my border lines down through the entire page as I was using the P…
Phishing attempts can come in all forms, shapes and sizes. No matter how familiar you think you are with them, always remember to take extra precaution when opening an email with attachments or links.
Familiarize people with the process of utilizing SQL Server functions 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 Microsoft Ac…
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.

829 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