Solved

Input mask for a textbox

Posted on 1997-04-04
3
697 Views
Last Modified: 2011-09-20
How do I have a input mask, like in Acces, for a text box.
I have tried Textbox1 = Format$(0000-0000000), for my telephone textbox. But user got to enter the -, can I display the - in the textbox.
Also how can I validate the data entered into the textbox, making sure that user enter the correct information. Is there a way that I can specify these checks in the properties. Upon error in the data entered, have a message to warn user. I have a lot of fields, do I have to create a msgbox for every field.
0
Comment
Question by:LarryTan
[X]
Welcome to Experts Exchange

Add your voice to the tech community where 5M+ people just like you are talking about what matters.

  • Help others & share knowledge
  • Earn cash & points
  • Learn & ask questions
3 Comments
 
LVL 1

Accepted Solution

by:
aktis earned 250 total points
ID: 1425051
The events you want are
1) KeyPress. Changing the KeyPress variable you can change one keystroke to another e.g. an non numberic ascii to "-"
2) LostFocus: fires when you leave the textbox and you can format the Text in the way you want

You can make a procedure with a parameter representing the current control. e.e.
Private Procedure RepairTelephone( cntrl as control)
    cntrl.Text=.......  
end sub
0
 

Author Comment

by:LarryTan
ID: 1425052
REgarding about the KeyPress event, can you be more specific about it, I have tried playing around but couldn't get it working. Please show me how its done.
0
 

Expert Comment

by:mhuber
ID: 1425053
Try adding a maskcontrol to your form.  Under properties enter the following for a phone number: ###-####.  By doing this your mask control will display the - mark and someone using your program will not have to enter it.  I usually name my mask controls like txtPhone, it's easier for me to keep up with it.  Here's the code I use in my lostfocus on this control.
Private Sub txtDate_LostFocus()
Dim I As Integer
DT1$ = Left$(txtDate.Text, 2): DT2$ = Mid$(txtDate.Text, 3, 2): DT3$ = Right$(Date$, 2)
CheckDate = DT1$ + ", " + DT2$ + ", " + DT3$
Print CheckDate
If IsDate(CheckDate) = False Then
   
beep: beep: beep: beep: beep: beep: beep
    Prompt = "Invalid date entered! Do you want to use today's date? " + txtDate.Text
   
    I = MsgBox(Prompt, vbYesNo)
If I = vbYes Then
    M1$ = Left$(Date$, 2): D1$ = Mid$(Date$, 4, 2): Y1$ = Right$(Date$, 2)
    UI$ = M1$ + "-" + D1$ + "-" + Y1$
    txtDate.Text = UI$
Else
    txtDate.SetFocus

End If
End If
End Sub

Hope this helps...if you need to contact me:  mhuber@peop.tdsnet.com
0

Featured Post

Salesforce Made Easy to Use

On-screen guidance at the moment of need enables you & your employees to focus on the core, you can now boost your adoption rates swiftly and simply with one easy tool.

Question has a verified solution.

If you are experiencing a similar issue, please ask a related question

Enums (shorthand for ‘enumerations’) are not often used by programmers but they can be quite valuable when they are.  What are they? An Enum is just a type of variable like a string or an Integer, but in this case one that you create that contains…
If you need to start windows update installation remotely or as a scheduled task you will find this very helpful.
As developers, we are not limited to the functions provided by the VBA language. In addition, we can call the functions that are part of the Windows operating system. These functions are part of the Windows API (Application Programming Interface). U…
Get people started with the utilization of class modules. Class modules can be a powerful tool in Microsoft Access. They allow you to create self-contained objects that encapsulate functionality. They can easily hide the complexity of a process from…

717 members asked questions and received personalized solutions in the past 7 days.

Join the community of 500,000 technology professionals and ask your questions.

Join & Ask a Question