Ignore current InputMask and give default value based on Keypress


I have a functional Help Desk Trouble Ticket Database.  This database is not much different than any other technical support desk trouble report database.

I have tickets input into the database with a default mask of "AHRS_EM"00000000;0;#

This gives the tickets a string value of "AHRS_EM00000001", and as normal the number increases sequentially.  

I MUST use the AHRS_EM part of the mask, as the tickets are compared to yet another database and it uses that format.


I have been asked if I can use my database to track non-standard tickets as well.  These tickets will not be counted like normal ones and I must track these separately.  So I decided to do that by having the user input the ticket with a number  starting with a 9 or 8 or 7.   This gives me millions of numbers to use before it might become a problem and I don't anticipate that ever becoming an issue.

So...  A standard ticket would be input with "00000021", "00000022", and so on....
While my (non-standard) tickets would be input with "99999999" or "88888888" or "77777777".  I only evaluate the first number to determine the type.  But the user must input ALL eight numbers in order to meet the criteria of the default mask.

If the first number typed starts with a 9, 8, or 7 then the database will dump the ticket input by the user, but take the first number and then assign a new ticket number based on the last ticket input.   i.e. user inputs 99999999, but the ticket is actually changed to 900000007 because the last ticket in the db is 90000006.


What I would like to do is, when the first number input meets my criteria, 9, 8, 7....
I would like the value automatically set to 77777777, 8888888, or 99999999. Instead of the user having to input the value, simply to meet the mask criteria.

I am trying to do this with the KeyPress and then evaluating the ASCII code so...

If KeyPress =  47 then Me.TT = "AHRS_EM99999999"


this does not change the field and the db still requires the rest of the number.

I have even tried If KeyPress = 47 then Me.TT.InputMask=""
(to eliminate the mask requirement)

But that hasn't work for me either.


Has anyone solved a problem like this before?

Who is Participating?
I thought SPermitEntryDate was the name of your textbox!
Yes, replace SPermitEntryDate with you textbox name,
and remove all the other [Event procedures] for the other keys (KeyPress or DownKey events).

I hate this kind of problem so just use code to do it.  On the After Update of the input text Box try this:

Select Case Right(TextBox,1)
   Case = 7
         Me.TT = "AHRS_EM" & YourValue
   Case = 8
         Me.TT = "AHRS_EM" & YourValue
end select

And so one.......
try it On Key up like this:

if Left(Me.TT.Text, 1)=9 or Left(Me.TT.Text, 1)=8 or Left(Me.TT.Text, 1)=7 then
 me.SPermitEntryDate.InputMask= "00000000;0;#"
me.SPermitEntryDate.InputMask= "'AHRS_EM'00000000;0;#"
Ultimate Tool Kit for Technology Solution Provider

Broken down into practical pointers and step-by-step instructions, the IT Service Excellence Tool Kit delivers expert advice for technology solution providers. Get your free copy now.

pooky2000Author Commented:

I haven't tried this solution yet, but...
If I implement this solution - wouldn't I still need to populate the entire text box before the AfterUpdate
would fire (since until the mask is satisfied, the AfterUpdate would error)?
pooky2000Author Commented:

SPermitEntryDate - is that a line from another db?  Would I replace that with my textbox name?

Do I do anything this the KeyPress or DownKey events?

Yes, In order to do that you would have to forsake your input mask and probably use a Validation Rule to force correct data entry.  Sorry I left that part out.  Maybe something like =7777777 OR = 8888888 OR =9999999.   Actually you can create fairly complex validation rules to apply to your input text box... Just a thought..
pooky2000Author Commented:

Thanks for the assistance.  I actually decided to place a button on the form to calculate the new TT value.

Why I didn't think of that before, I don't know...  

But I appreciate all the help.

Could you tell me why it was important to put the code on the keyup rather than the keydown?
Very interesting question,

I have been working on a project where I have a Listbox, and I needed to select multiple entries and be able to double click,
I had to go through the trial and error to find the best solution,

Athough you use keys, I used Mouse, which at the end are sort of similar.

Besides, before I answered you question, I tried it and got the results desired.

Question has a verified solution.

Are you are experiencing a similar issue? Get a personalized answer when you ask a related question.

Have a better answer? Share it in a comment.

All Courses

From novice to tech pro — start learning today.