I do not want to allow any special characters to be entered into a field

  • Thread starter moe leaer via AccessMonster.com
  • Start date
M

moe leaer via AccessMonster.com

I currently have part numbers that have DASHES in various locations throughout the alpha numeric number. I have convinced the company that for sorting and Database reasons it would be better if users do NOT enter the dashes in the database.

I would like to set up something that would either not allow them to enter the -'s or even better, just remove them automatically before the form print function.

The INPUT Mask function sort of does what I want, but OUR alpha numeric part numbers are of various lengths, from 4-20 characters. It seems to put place holders in the remanding places that are a bit strange looking.

Any Ideas, thanks for the help!

Moe
 
D

Duane Hookom

I hate input masks so I would use code in the form to either ignore the "-"
or replace is with "" following the updating of the control.
Private Sub txtPartNum_KeyPress(KeyAscii As Integer)
'ignore the "-"
If KeyAscii = Asc("-") Then
KeyAscii = 0
End If
End Sub

--
Duane Hookom
MS Access MVP


moe leaer via AccessMonster.com said:
I currently have part numbers that have DASHES in various locations
throughout the alpha numeric number. I have convinced the company that for
sorting and Database reasons it would be better if users do NOT enter the
dashes in the database.
I would like to set up something that would either not allow them to enter
the -'s or even better, just remove them automatically before the form print
function.
The INPUT Mask function sort of does what I want, but OUR alpha numeric
part numbers are of various lengths, from 4-20 characters. It seems to put
place holders in the remanding places that are a bit strange looking.
 
J

John Vinson

I currently have part numbers that have DASHES in various locations throughout the alpha numeric number. I have convinced the company that for sorting and Database reasons it would be better if users do NOT enter the dashes in the database.

Good! I'd hate to think that "A312-2" and "A31-22" would both be valid
part numbers, whether they refer to the same part or to different
parts.
I would like to set up something that would either not allow them to enter the -'s or even better, just remove them automatically before the form print function.

What does the "print" function have to do with anything!? You're not
printing a Form, I hope?
The INPUT Mask function sort of does what I want, but OUR alpha numeric part numbers are of various lengths, from 4-20 characters. It seems to put place holders in the remanding places that are a bit strange looking.

Any Ideas, thanks for the help!

Two suggestions:

- Use the BeforeUpdate event of the part number textbox to chide the
user for invalid part numbers:

Private Sub txtPartNo_BeforeUpdate(Cancel as Integer)
If InStr(txtPartNo, "-") > 0 Then
MsgBox "Please, no hyphens!", vbOKOnly
Cancel = True
End If

Or, a bit more code: use the AfterUpdate event (sounds illogical but
it's the correct event) to strip them out:

Private Sub txtPartNo_AfterUpdate()
Dim iPos As Integer
Dim sChr As String
Dim sFix As String
txtPartNo = UCase(txtPartNo) ' upper case all text
sFix = ""
For iPos = 1 to Len(txtPartNo)
sChr=Mid(txtPartNo, iPos, 1)
If (Asc(sChr) >= 48 And Asc(sChr) <= 57) ' digits
Or (Asc(sChr) >= 65 And Asc(sChr) <= 90) Then ' letters
sFix = sFix & sChr
Else
' either do nothing, or
' MsgBox "Stripping out invalid part number characters", vbOKOnly
End If
Next iPos
txtPartNo = sFix
End Sub

John W. Vinson[MVP]
Join the online Access Chats
Tuesday 11am EDT - Thursday 3:30pm EDT
http://community.compuserve.com/msdevapps
 

Ask a Question

Want to reply to this thread or ask your own question?

You'll need to choose a username for the site, which only take a couple of moments. After that, you can post your question and our members will help you out.

Ask a Question

Top