Tek-Tips is the largest IT community on the Internet today!

Members share and learn making Tek-Tips Forums the best source of peer-reviewed technical information on the Internet!

  • Congratulations gkittelson on being selected by the Tek-Tips community for having the most helpful posts in the forums last week. Way to Go!

Input Mask 3

Status
Not open for further replies.

JSD

Technical User
Jan 18, 2002
189
US
Hello,

I was wondering if someone can help me with an input mask for a particular field. The values to be entered in this field should be restricted to numbers only, and it will either be a four digit number or a four digit number, a dash, and a two digit number.

ex -- "1000"
"1000-10"
"2100"
"3000-10"

Any ideas are much appreciated as always.

Thanks

Jeremy
 
Jeremy

I am guessing that this is in a text field on a form.
Place this code in the text field after_update event.

Where there is "your_text_field_name" replace it with the name of your text box

'copy from here
Dim field_length As Integer
Dim dash_position As Integer

field_length = Len(Me.your_text_field_name)

Select Case field_length
Case 4
'now test the field if it is a number
If IsNumeric(Me.your_text_field_name) = False Then
'not in the correct format
Me.your_text_field_name.SetFocus
MsgBox "Please correct as this field is not in the correct format"
End If
Case 7
'ensure the dash is in the correct position
dash_position = InStr(Me.your_text_field_name, "-")
Select Case dash_position
Case 5
If IsNumeric(Left(Me.your_text_field_name, 4)) And IsNumeric(Right(Me.your_text_field_name, 2)) = False Then
'not in the correct format
Me.your_text_field_name.SetFocus
MsgBox "Please correct as this field is not in the correct format"
End If
Case Else
'not in the correct format
Me.your_text_field_name.SetFocus
MsgBox "Please correct as this field is not in the correct format"
End Select
Case Else
'not in the correct format
Me.your_text_field_name.SetFocus
MsgBox "Please correct as this field is not in the correct format"
End Select
'end copy

Enjoy
Tiny

Perfection is Everything
If it worked first time we wont be here!
 
If no calculations are need for this field, use TEXT as datatype for this field with a length of 6.

Input Mask : 0000\-99

No need for code !
 
Thanks guys,

Both methods work great!

Jeremy


 
Here's my thought: input masks are the devil's work. I HATE using forms that have input masks, because if you click into the field with your mouse you will be at a specific place within the mask depending upon where you clicked, and that becomes a real pain to deal with. And the same is true if you tab into the control when there's already data in there.

I would break this into two controls. It should certainly be stored in to different fields, unless you will _never_ search or sort based on either part of this data. And it would be easy enough to put a label between the two controls with a dash. And, of course, you can always display these two values as one by concatenating with the dash between them.

Jeremy

==
Jeremy Wallace
AlphaBet City Dataworks
Access Databases for Non-Profit Organizations

Please post in the appropriate forum with a descriptive subject; code and SQL, if referenced; and expected results. See thread181-473997 for more pointers.
 
Hello JeremyNYC,

Haven't heard from you in a while. I appreciate your opinion. The only problem is that user is scanning a barcode off a work order to get the value. Are you suggesting using concatenate in the form, and when user scans the barcode the values update in two different fields?

The other thing is that I'm linked to an SQL table on our network - I need the final value in one field, as the field is on the SQL table.

Thanks for your thoughts,

Jeremy

P.S. - Still learning
 
Jeremy,

Yeah, I've been pretty busy lately. Should be working right now, but I'm having a hard time motivating, so...

If you're scanning the data, shouldn't you use a format, not an input mask? Oh, well I guess it makes sense that you're scanning when viewing a form. I would go with p27br's solution. I tend to store things with no formating, and do all of that in queries or on the forms or reports where stuff is displayed, but if that's how it's set up in someone else's database, you'll have to play by their rules.

Jeremy

==
Jeremy Wallace
AlphaBet City Dataworks
Access Databases for Non-Profit Organizations

Please post in the appropriate forum with a descriptive subject; code and SQL, if referenced; and expected results. See thread181-473997 for more pointers.
 
Status
Not open for further replies.

Part and Inventory Search

Sponsor

Back
Top