Solved

Input mask for a textbox

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

Enroll in May's Course of the Month

May’s Course of the Month is now available! Experts Exchange’s Premium Members and Team Accounts have access to a complimentary course each month as part of their membership—an extra way to increase training and boost professional development.

Question has a verified solution.

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

If you have ever used Microsoft Word then you know that it has a good spell checker and it may have occurred to you that the ability to check spelling might be a nice piece of functionality to add to certain applications of yours. Well the code that…
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…
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 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…

739 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