By using this site, you agree to our updated Privacy Policy and our Terms of Use. Manage your Cookies Settings.
425,460 Members | 2,215 Online
Bytes IT Community
+ Ask a Question
Need help? Post your question and get tips & solutions from a community of 425,460 IT Pros & Developers. It's quick & easy.

Error Handling: Incorrect Information Input

P: 23
I have a textbox in which the user will be entering serial numbers (all desired data is in the form of: s********) representing "type"(serial number - s) followed by the number.

I have a split function that inputs the data based on the delimiter 's' shown below:

Expand|Select|Wrap|Line Numbers
  1. Dim InputString() As String
  2. Dim i As Integer
  3. InputString = Split(InputName, "s")
  4. For i = 1 To UBound(InputString)
  5.     CurrentDb.Execute "INSERT INTO InventoryInputT(InputID) VALUES ('" & InputString(i) & "')"
  6. Next i
  7.  
creating individual records regardless of the number of inputs.


Is there a way to implement some code so that an error message comes up if the user inputs anything that doesn't start with and s?

Example, user data input is
Expand|Select|Wrap|Line Numbers
  1. s101 s202 p303 p404 s505
Regardless of how many correct inputs there are (the s) I would like an error message to appear that states "invalid code scanned" and then moving to another new record where they have to rescan the data and reenter it.

In this particular case, the statement might be "incorrect scan, p encountered, please rescan and reenter".... user clicks "okay".... form reopens with another "New Record".

Thank you
May 16 '17 #1

✓ answered by NeoPa

TylerBennett:
What does the suggested code do, particularly with regard to the "* [^s]*" ?
What it does is match any space (' ') in the string when it is followed by any character other than an 's'. The asterisks (*) match zero or more of any characters. Anything withing the brackets ([]) is considered as a list of characters that can be matched, unless the first character is a carat (^) in which case it matches anything except characters in the list.

Oooops! I just realised I mixed up my Access Matching with my Regular Expressions. That should be an exclamation mark (or bang!) rather than a carat (^). They have the same effect but in different places. For Jet/ACE in Access use the following instead :
Expand|Select|Wrap|Line Numbers
  1. If " " & InputName Like "* [!s]*" Then
  2.     ...
  3. End If
Sorry about that :-(

Share this Question
Share on Google+
5 Replies


NeoPa
Expert Mod 15k+
P: 31,398
How about :
Expand|Select|Wrap|Line Numbers
  1. If " " & InputName Like "* [^s]*" Then
  2.     ...
  3. End If
May 17 '17 #2

P: 23
Thanks for responding,

I will start messing around with this code but if you or somebody gets to it, a couple questions:

1) Would I put my above code within the if statement or after the statement?

2) What does the suggested code do, particularly with regard to the "* [^s]*" ?

Thanks.
May 24 '17 #3

P: 23
The code does work however I have one hiccup,

Correct Input:
Expand|Select|Wrap|Line Numbers
  1. s11
  2. s22
  3.  
Upon "save" this does save, perfect

Incorrect input:
Expand|Select|Wrap|Line Numbers
  1. p11
  2. p22
  3.  
Upon Save "Error" message appears, perfect

Incorrect input:
Expand|Select|Wrap|Line Numbers
  1. p11
  2. s11
  3.  
Upon save, "Error" occurs, perfect

Incorrect Input
Expand|Select|Wrap|Line Numbers
  1. s11
  2. p22
  3.  
Upon Save, it actually saves s11 and not p22, which is technically valid. However, I have to assume the operators don't know what they're doing, and therefore would like the code to search the entire textbox and if it encounters the 'p' then ALL data has to be reentered... in the above example, the s11 should not be saved.

As such, the error currently seems to be that it looks at the beginning string of each entry rather than view the dataset as a whole.

My code for the implementation of this is currently:

Expand|Select|Wrap|Line Numbers
  1. If " " & InputName Like "* [^p]*" Then
  2.     MsgBox "Error"
  3.  
  4. Else
  5.     InputString = Split(InputName, "s")
  6.     For i = 1 To UBound(InputString)
  7.         CurrentDb.Execute "INSERT INTO InventoryInputT(InputID) VALUES ('" & InputString(i) & "')"
  8.     Next i
  9. End If
  10.  
Thank you.
May 24 '17 #4

jforbes
Expert 100+
P: 1,107
Are you using a Keyboard-Wedge style scanner? If so, you might want to check into the Keydown Event (maybe Keypress) to capture the string of characters as they come in, instead of after it's moved focus all over your screen.
May 24 '17 #5

NeoPa
Expert Mod 15k+
P: 31,398
TylerBennett:
What does the suggested code do, particularly with regard to the "* [^s]*" ?
What it does is match any space (' ') in the string when it is followed by any character other than an 's'. The asterisks (*) match zero or more of any characters. Anything withing the brackets ([]) is considered as a list of characters that can be matched, unless the first character is a carat (^) in which case it matches anything except characters in the list.

Oooops! I just realised I mixed up my Access Matching with my Regular Expressions. That should be an exclamation mark (or bang!) rather than a carat (^). They have the same effect but in different places. For Jet/ACE in Access use the following instead :
Expand|Select|Wrap|Line Numbers
  1. If " " & InputName Like "* [!s]*" Then
  2.     ...
  3. End If
Sorry about that :-(
May 25 '17 #6

Post your reply

Sign in to post your reply or Sign up for a free account.