Solved

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

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

Enabling OSINT in Activity Based Intelligence

Activity based intelligence (ABI) requires access to all available sources of data. Recorded Future allows analysts to observe structured data on the open, deep, and dark web.

Join & Write a Comment

This article is a continuation or rather an extension from Cascading Combos (http://www.experts-exchange.com/A_5949.html) and builds on examples developed in detail there. It should be understandable alone, but I recommend reading the previous artic…
Describes a method of obtaining an object variable to an already running instance of Microsoft Access so that it can be controlled via automation.
In Microsoft Access, when working with VBA, learn some techniques for writing readable and easily maintained code.
Access reports are powerful and flexible. Learn how to create a query and then a grouped report using the wizard. Modify the report design after the wizard is done to make it look better. There will be another video to explain how to put the final p…

708 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

14 Experts available now in Live!

Get 1:1 Help Now