Want to win a PS4? Go Premium and enter to win our High-Tech Treats giveaway. Enter to Win

x
?
Solved

Input mask for a textbox

Posted on 1997-04-04
3
Medium Priority
?
702 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 750 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

Free Tool: Site Down Detector

Helpful to verify reports of your own downtime, or to double check a downed website you are trying to access.

One of a set of tools we are providing to everyone as a way of saying thank you for being a part of the community.

Question has a verified solution.

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

This article describes some techniques which will make your VBA or Visual Basic Classic code easier to understand and maintain, whether by you, your replacement, or another Experts-Exchange expert.
If you need to start windows update installation remotely or as a scheduled task you will find this very helpful.
Get people started with the process of using Access VBA to control Outlook using automation, Microsoft Access can control other applications. An example is the ability to programmatically talk to Microsoft Outlook. Using automation, an Access applic…
Show developers how to use a criteria form to limit the data that appears on an Access report. It is a common requirement that users can specify the criteria for a report at runtime. The easiest way to accomplish this is using a criteria form that a…
Suggested Courses

597 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