Solved

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

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

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 58

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 50

Expert Comment

by:Gustav Brock
ID: 40590915
You are welcome!

/gustav
0

Featured Post

Back Up Your Microsoft Windows Server®

Back up all your Microsoft Windows Server – on-premises, in remote locations, in private and hybrid clouds. Your entire Windows Server will be backed up in one easy step with patented, block-level disk imaging. We achieve RTOs (recovery time objectives) as low as 15 seconds.

Question has a verified solution.

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

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 …
The Windows Phone Theme Colours is a tight, powerful, and well balanced palette. This tiny Access application makes it a snap to select and pick a value. And it doubles as an intro to implementing WithEvents, one of Access' hidden gems.
Familiarize people with the process of retrieving data from SQL Server using an Access pass-thru query. Microsoft Access is a very powerful client/server development tool. One of the ways that you can retrieve data from a SQL Server is by using a pa…
In Microsoft Access, learn how to “cascade” or have the displayed data of one combo control depend upon what’s entered in another. Base the dependent combo on a query for its row source: Add a reference to the first combo on the form as criteria i…

717 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