Solved

Input mask for a textbox

Posted on 1997-04-04
3
689 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
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

Is Your Active Directory as Secure as You Think?

More than 75% of all records are compromised because of the loss or theft of a privileged credential. Experts have been exploring Active Directory infrastructure to identify key threats and establish best practices for keeping data safe. Attend this month’s webinar to learn more.

Question has a verified solution.

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

I’ve seen a number of people looking for examples of how to access web services from VB6.  I’ve been using a test harness I built in VB6 (using many resources I found online) that I use for small projects to work out how to communicate with web serv…
Since upgrading to Office 2013 or higher installing the Smart Indenter addin will fail. This article will explain how to install it so it will work regardless of the Office version installed.
Get people started with the process of using Access VBA to control Excel using automation, Microsoft Access can control other applications. An example is the ability to programmatically talk to Excel. Using automation, an Access application can laun…
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…

911 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

Need Help in Real-Time?

Connect with top rated Experts

15 Experts available now in Live!

Get 1:1 Help Now