VB code for input mask in MS Access

Status
Not open for further replies.

ringo1079

Ars Praefectus
3,421
Subscriptor
Hello all!

I'm trying to figure out a way to force the user to enter in two numeric digits and only two digits in a query.

I know that if you enter a "0" for the input mask its suppose to FORCE entry for that digit, but that isnt the case, it will accept nothing.

Does anyone know of any VB code that can be written for this?

Any insight would be greatly appreciated
Thanks in advance...
CJK
 

ak6ar

Seniorius Lurkius
34
Hmm I am not sure exactly how to do that (I don't do very much MS Access programming).

But I did run accross this msdn kb article you might want to check out. It talks about flexible input masks for zip code (5 or 9) but you should be able to adapt that code to what you need pretty quickly I am guessing. (Oh yes this is assuming you are talking about a form input in VB in MS Access).

MSDN KB Article
 

ringo1079

Ars Praefectus
3,421
Subscriptor
alright...i opened up a form in design view and attempted to add in that ActiveX control, and this is what i got...

You don't have the license required to use this ActiveX control.

You tried to open a form containing an OLE object or an ActiveX control or you tried to create an ActiveX control.

To obtain the appropriate license, contact the company that provides
the licensed OLE object or ActiveX control.

??? does this mean that i dont have a professional version of Access or something???
 

DaleDBeast

Wise, Aged Ars Veteran
172
This code works on an ordinary Access textbox. The "KeyAscii" argument is allowing you to modify the character entered at the keyboard before it is displayed back to the user.


Private Sub Text1_KeyPress(KeyAscii As Integer)
With Text1
Select Case KeyAscii
Case 8
'allow backspace key by not changing KeyAscii

Case 48 To 57
'allow the numbers 0-9 by not changing KeyAscii

'deny inputs past 2 characters by discarding KeyAscii
If Len(.Text) >= 2 Then KeyAscii = 0

Case Else
'deny all other inputs by discarding KeyAscii
KeyAscii = 0

End Select
End With
End Sub
 
Status
Not open for further replies.