-
Sep 22nd, 2018, 06:13 AM
#1
Thread Starter
New Member
How to check no. of characters in a textbox
HI,
I am creating a form where I want to enter a mobile number in a text box.
The mobile number is of 10 digits only
If it is Less than 10 digits or more than then 10 digits, I want to display a message box which says "Enter a valid number"
Please help.
I am fairly new to VBA.
-
Sep 22nd, 2018, 12:52 PM
#2
Re: How to check no. of characters in a textbox
1) Restrict your textbox to digits only input --> Tons of examples here
2) You can use Len(MyTextBox.Text) to check for length --> If Len(MyTextBox.Text)<>10 Then MsgBox("KaBoom!")
Last edited by Zvoni; Tomorrow at 31:69 PM.
----------------------------------------------------------------------------------------
One System to rule them all, One Code to find them,
One IDE to bring them all, and to the Framework bind them,
in the Land of Redmond, where the Windows lie
---------------------------------------------------------------------------------
People call me crazy because i'm jumping out of perfectly fine airplanes.
---------------------------------------------------------------------------------
Code is like a joke: If you have to explain it, it's bad
-
Sep 22nd, 2018, 01:01 PM
#3
Re: How to check no. of characters in a textbox
VBA questions should go into the VBA forum (MS Office), not VB. The environment is different enough to make answers to questions different even when the core programming syntax is similar.
-
Sep 22nd, 2018, 01:03 PM
#4
Re: How to check no. of characters in a textbox
Huh?
Missed the last line in the first post.
Last edited by Zvoni; Tomorrow at 31:69 PM.
----------------------------------------------------------------------------------------
One System to rule them all, One Code to find them,
One IDE to bring them all, and to the Framework bind them,
in the Land of Redmond, where the Windows lie
---------------------------------------------------------------------------------
People call me crazy because i'm jumping out of perfectly fine airplanes.
---------------------------------------------------------------------------------
Code is like a joke: If you have to explain it, it's bad
-
Sep 22nd, 2018, 09:06 PM
#5
Re: How to check no. of characters in a textbox
You can also set the max length of a text box which will restrict entry to no more than the given number of characters.
You also have the option of using the masked edit box which will give you more control over the format of the entry and the way it is displayed to the user.
-
Sep 23rd, 2018, 08:54 AM
#6
Re: How to check no. of characters in a textbox
As suggested by datamiser:
Place a masked edit control on your form (add the component: "Microsoft Masked Edit Control 6.0" to your ToolBox)
In its Mask Property, type "###-###-####" (without the quotes)
Change the Prompt Include Property to FALSE
That is all you should need.
Posting Permissions
- You may not post new threads
- You may not post replies
- You may not post attachments
- You may not edit your posts
-
Forum Rules
|
Click Here to Expand Forum to Full Width
|