-
Re: How to restrict users to enter first character as alphabet and rest as numeric.
Obviously things have evolved since this post began.
I have re-read (quickly) and think that the last example I posted will infact
do what you after (in it's entirity).
It will alert the user if they enter anything other than an Alpha character at the start of the entry.
It will also cater for ANY paste operation, alerting the user if unwanted data was pasted.
In short (from the tests I did) you need no other code at all to validate the entry.
Good luck with your project :)
Bruce.
-
Re: How to restrict users to enter first character as alphabet and rest as numeric.
Hey Bruce! Indeed this thread has gone a long way!! Thanks to all the good people out here. :wave:
Do you mean that all I need is this code below that you posted??
Quote:
Ok, how is this:
VB Code:
Option Explicit
Private Sub Text1_Change()
Call Validate_Entry(Text1, Text1.Text)
End Sub
Private Sub Text2_Change()
Call Validate_Entry(Text2, Text2.Text)
End Sub
Private Function Validate_Entry(ByRef txtBox As TextBox, ByVal strBuff As String) As Boolean
If UCase(Left$(strBuff, 1)) Like "[A-Z]" Then
'do nothing
Else
MsgBox "Please try again.", vbOKOnly + vbInformation, "Invalid Entry"
txtBox.SelStart = 0
txtBox.SelLength = Len(strBuff)
End If
End Function
The above takes care of regular keyboard input AND paste operations.
Bruce.
What about of Baja's code?
Well, I tried yours alone and sad to say it's not working as you said it would...
Hope you could re-check...
Thanks!
-
Re: How to restrict users to enter first character as alphabet and rest as numeric.
Actually my code (not my code, the code from the link I provided) works!
The context menu does show, but past will yield no results. It will not paste the data.
-
Re: How to restrict users to enter first character as alphabet and rest as numeric.
Quote:
Originally Posted by seraphicmortal
Do you mean that all I need is this code below that you posted??
Yep...
Quote:
Originally Posted by seraphicmortal
Well, I tried yours alone and sad to say it's not working as you said it would...
Hmmm, I successfully tested it (a few times) prior to posting it. What isn't it doing
that it should? (maybe something I missed in the translation) :)
Bruce.
-
Re: How to restrict users to enter first character as alphabet and rest as numeric.
And.... a slight tweek:
VB Code:
Option Explicit
Private Sub Text1_Change()
Call Validate_Entry(Text1, Text1.Text)
End Sub
Private Sub Text2_Change()
Call Validate_Entry(Text2, Text2.Text)
End Sub
Private Function Validate_Entry(ByRef txtBox As TextBox, ByVal strBuff As String) As Boolean
If UCase(Left$(strBuff, 1)) Like "[A-Z]" Or Left$(strBuff, 1) = vbNullString Then
'do nothing
Else
MsgBox "Please try again.", vbOKOnly + vbInformation, "Invalid Entry"
txtBox.Text = ""
End If
End Function
I retested with pasting say "123today" and general keyboard (KeyPresses) of different characters.
All leading Numeric entries were blocked and an alert given.
Bruce.
-
Re: How to restrict users to enter first character as alphabet and rest as numeric.
-
Re: How to restrict users to enter first character as alphabet and rest as numeric.
Well, your code sure doesn't allow text entry tru context menu (right-click) that doesn't conform to the (alpha then rest numeric) format and if 1st key-in is an integer BUT when you just key-in "abcd" (all alpha characters, your code still accepts that string.
-
Re: How to restrict users to enter first character as alphabet and rest as numeric.
Ok :)
VB Code:
Option Explicit
Private Sub Text1_Change()
Call Validate_Entry(Text1)
End Sub
Private Sub Text2_Change()
Call Validate_Entry(Text2)
End Sub
Private Sub Validate_Entry(ByRef txtBox As TextBox)
If Left$(txtBox.Text, 1) <> vbNullString Then
If UCase(txtBox.Text) Like "[A-Z]" & String(Len(txtBox.Text) - 1, "#") And Len(txtBox.Text) < 6 Then
'Do nothing
Else
MsgBox "Please try again.", vbOKOnly + vbInformation, "Invalid Entry"
txtBox.Text = ""
End If
End If
End Sub
Input format = annnn
Maximum of 5 characters (first Alpha, remaing Numeral)
Bruce.
-
1 Attachment(s)
Re: How to restrict users to enter first character as alphabet and rest as numeric.
If you're passing a reference to the text box to the function why do you need to pass the text as well? Can't the function just read the Text property? Why have you made this into a function when you never return anything? I also don't like that the function clears the textbox everytime you enter a bad character. It would be better to just indicate that the text format is wrong in some way. Perhaps by changing the color of the textbox to red.
I also think that you should combine Bruce's code with the one you had earlier from baja_yu that restricted input during the KeyPress event. The Change event can then be used as an extra precausion if the user have pasted illegal characters.
I also like to wrap these kind of things up in a handy class that handles everything. That way you can simply create an object of the class initilize it and then forget about it :)
I've attached such a class that uses Bruce's and Baja_yu's code with only slight changes. The changes is mainly cosmetic, first of all instead of only allowing you to type at the end of the text as baya_yu's code you can put the text caret anywhere in the text and just start typing. If you are at the beginning of the text and press a alpha key it will automatically replace the first character with the new one. If you paste text that is invalid the backcolor of the textbox will turn red (by default, you can change that color if you wish). As an extra optional feature you can assign your own popup menu that will replace the default, so you can remove the Cut and Paste if you wish by simply create your own menu. This is how you use it:
VB Code:
Private oValidateText As CTextFormat
Private Sub Form_Load()
Set oValidateText = New CTextFormat
Set oValidateText.TextBox = Text1
End Sub
That's it, the rest is done by the class. The class has 3 properties you can set.
* TextBox = Assign the text box as shown above.
* ContextMenu = Assign a custom popup menu (using the Set keyword)
* ErrorColor = Assign the color the textbox will get if you paste invalid text (default is red)
The class also have one method called Init which you can use to set all the above properties at once, like this:
VB Code:
Call oValidateText.Init(Text1, vbYellow, mnuPopUp)
Only the first argument of the Init method is required the other two are optional. If you assign your own context menu the Paste command will automatically disappear (if you don't have a Paste in your menu of course) and you will not be able to paste using Ctrl+V either.
-
Re: How to restrict users to enter first character as alphabet and rest as numeric.
@Joacim. Oh, I totaly missed the (misuse) of the Function - my bad, was a hangover from the true functio (that returned a Boolean)
and the Text by Ref certanly can be used, I just (inadvertantly) followed what I had from the start.
Bruce.
-
Re: How to restrict users to enter first character as alphabet and rest as numeric.
Hi! Joacim! I'd like to know if it would possible for you to just post the codes (using vb tags) for easy viewing...and basically because I can't download zip files...hehe sorry for that. Please... ;)
-
Re: How to restrict users to enter first character as alphabet and rest as numeric.
OK, create a new class and paste this code to it.
VB Code:
Option Explicit
Private WithEvents txtBox As TextBox
Private mnuContext As Menu
Private m_ErrorColor As Long
Public Sub Init(TextBox As TextBox, _
Optional ErrorColor As Long = vbRed, _
Optional ContextMenu As Menu = Nothing)
Set mnuContext = ContextMenu
m_ErrorColor = ErrorColor
Set txtBox = TextBox
End Sub
Public Property Get ErrorColor() As Long
ErrorColor = m_ErrorColor
End Property
Public Property Let ErrorColor(nNew As Long)
m_ErrorColor = nNew
End Property
Public Property Set TextBox(txt As TextBox)
Set txtBox = txt
End Property
Public Property Get TextBox() As TextBox
Set TextBox = txtBox
End Property
Public Property Set ContextMenu(mnu As Menu)
Set mnuContext = mnu
End Property
Public Property Get ContextMenu() As Menu
Set ContextMenu = mnuContext
End Property
Private Sub Class_Initialize()
m_ErrorColor = vbRed
End Sub
Private Sub txtBox_Change()
Dim nSelStart As Long, nSelLen As Long
If Len(txtBox.Text) Then
If (UCase$(txtBox.Text) Like "[A-Z]" & String(Len(txtBox.Text) - 1, "#")) Then
If UCase$(txtBox.Text) <> txtBox.Text Then
nSelStart = txtBox.SelStart
nSelLen = txtBox.SelLength
txtBox.Text = UCase$(txtBox.Text)
txtBox.SelStart = nSelStart
txtBox.SelLength = nSelLen
End If
txtBox.BackColor = vbWindowBackground
Else
txtBox.BackColor = m_ErrorColor
End If
Else
txtBox.BackColor = vbWindowBackground
End If
End Sub
Private Sub txtBox_KeyPress(KeyAscii As Integer)
Dim nSelLen As Long
nSelLen = txtBox.SelLength
If txtBox.SelStart = 0 And txtBox.SelLength = 0 Then
'This will ensure that the first character is replaced if
'the user has moved the text caret to the beginning of the text
txtBox.SelLength = 1
End If
KeyAscii = Asc(UCase$(Chr$(KeyAscii))) 'capitilize
Select Case KeyAscii
Case vbKeyBack
txtBox.SelLength = nSelLen
Case vbKeyA To vbKeyZ
If txtBox.SelStart <> 0 Then
KeyAscii = 0
txtBox.SelLength = nSelLen
End If
Case vbKey0 To vbKey9
If txtBox.SelStart = 0 Then
KeyAscii = 0
txtBox.SelLength = nSelLen
End If
Case Else
KeyAscii = 0
txtBox.SelLength = nSelLen
End Select
End Sub
Private Sub txtBox_MouseDown(Button As Integer, Shift As Integer, X As Single, Y As Single)
If Not mnuContext Is Nothing Then
If Button And vbRightButton Then
'surpress the default context menu and show our custom menu instead
txtBox.Enabled = False
txtBox.Enabled = True
txtBox.Parent.PopupMenu mnuContext
End If
End If
End Sub
-
Re: How to restrict users to enter first character as alphabet and rest as numeric.
Hey Bruce, Your code worked great!!! ;) It does take care the pasting issue. One thing though, is it possible to change the alpha(1st Character input) capital as the user would type it or paste it?? Can you amend your code please?
-
Re: How to restrict users to enter first character as alphabet and rest as numeric.
Joacim,
I have since fixed up the input limit too, maybe you can roll this into the class code.
VB Code:
If UCase(txtBox.Text) Like "[A-Z]" & String(Len(txtBox.Text) - 1, "#") [b]And Len(txtBox.Text) < 6[/b] Then
Bruce.
-
Re: How to restrict users to enter first character as alphabet and rest as numeric.
My first thought....
VB Code:
Option Explicit
Private Sub Text1_Change()
Call Validate_Entry(Text1)
End Sub
Private Sub Text2_Change()
Call Validate_Entry(Text2)
End Sub
Private Sub Validate_Entry(ByRef txtBox As TextBox)
If Left$(txtBox.Text, 1) <> vbNullString Then
If UCase(txtBox.Text) Like "[A-Z]" & String(Len(txtBox.Text) - 1, "#") And Len(txtBox.Text) < 6 Then
txtBox.Text = UCase(txtBox.Text)
txtBox.SelStart = Len(txtBox.Text)
Else
MsgBox "Please try again.", vbOKOnly + vbInformation, "Invalid Entry"
txtBox.Text = ""
End If
End If
End Sub
However, Joacim has provided a portable option - the class can be tweeked to suit other apps too :)
Bruce.
-
Re: How to restrict users to enter first character as alphabet and rest as numeric.
Quote:
Originally Posted by Bruce Fox
I have since fixed up the input limit too, maybe you can roll this into the class code.
I didn't find that necassary since you could just as well set the MaxLength property of the TextBox and it will fix that automatically.
-
Re: How to restrict users to enter first character as alphabet and rest as numeric.
Quote:
Originally Posted by Joacim Andersson
I didn't find that necassary since you could just as well set the MaxLength property of the TextBox and it will fix that automatically.
Good point ;)
Bruce.
-
Re: How to restrict users to enter first character as alphabet and rest as numeric.
Thank you so much you guys esp. to you Bruce!! ;) I think you code covers all the issues in my question. Bravo to you!!
-
Re: How to restrict users to enter first character as alphabet and rest as numeric.
wellllll, since everyone one else has been messing with this, I thought I'd give it a try :)
VB Code:
Private Sub Text1_Change()
Text1.Text = TestFormat(Text1.Text)
End Sub
Private Function TestFormat(ByVal Text As String) As String
Dim lMaxLen As Long
lMaxLen = 4 ' or how ever long you want it to be
If Len(Text) > lMaxLen Then Exit Function
If InStr(1, "abcdefghijklmnopqrstuvwxyz", Left$(Text, 1), vbTextCompare) Then
If IsNumeric(Mid$(Text, 2)) Or Len(Text) = 1 Then
Mid$(Text, 1, 1) = UCase$(Mid$(Text, 1, 1))
TestFormat = Text
End If
End If
End Function
-
Re: How to restrict users to enter first character as alphabet and rest as numeric.
Yeah, but your code erases the whole input if an invalid character is entered.
Most users would find that extremely annoying.
-
Re: How to restrict users to enter first character as alphabet and rest as numeric.
I don't think seraphicmortal fully explored the class I uploaded. Since that allows you to change the popup menu that is used when you right click the textbox you can either remove the Paste command or implement your own Paste procedure in which you of course have full control of the Paste procedure. That means you can examine the clipboard content before you insert it and edit the content so you don't paste any illegal characters.
-
Re: How to restrict users to enter first character as alphabet and rest as numeric.
Sometimes I like annoying ppl };)
Ok, this is better then
VB Code:
Private Sub Text1_Change()
Text1.Text = TestFormat(Text1.Text)
Text1.SelStart = Len(Text1.Text)
End Sub
Private Function TestFormat(ByRef Text As String) As String
Dim sAlpha As String
Dim lX As Long
Dim lMaxLen As Long
If Len(Text) = 0 Then Exit Function
lMaxLen = 4 ' or how ever long you want it to be
sAlpha = "abcdefghijklmnopqrstuvwxyz"
Do While InStr(1, sAlpha, Left$(Text, 1), vbTextCompare) = 0
Text = Mid$(Text, 2)
If Len(Text) = 0 Then Exit Function
Loop
For lX = 2 To Len(Text)
If Not IsNumeric(Mid$(Text, lX, 1)) Then
Mid$(Text, lX, 1) = Chr$(0)
End If
Next
Text = Replace$(Text, Chr$(0), vbNullString)
If Len(Text) > lMaxLen Then
Text = Left$(Text, lMaxLen)
End If
TestFormat = UCase$(Text)
End Function
-
Re: How to restrict users to enter first character as alphabet and rest as numeric.
Well the thread started has marked it as resolved so we could just stop posting :). BTW baja_yu, thanks for the rating.
-
Re: How to restrict users to enter first character as alphabet and rest as numeric.
Hey Joacim, I'm still gona try ur suggestion though!! ;) Thanks for the inputs. =)
-
Re: How to restrict users to enter first character as alphabet and rest as numeric.
@seraphicmortal: I got your PM but I don't understand what it is that gives you the error. Are you trying to assign a menu to the class?
-
Re: How to restrict users to enter first character as alphabet and rest as numeric.
I just pasted ur code to my program and change txtbox to the name of my textbox and placed the following in my global.bas:
VB Code:
Public mnuContext As New txtbox
Public mErrorColor As Long
then in my frm_field(form where my textbox are placed):
VB Code:
Private Sub txt_qty_Change()
' Call Validate_Entry(txt_qty)
Dim nSelStart As Long, nSelLen As Long
If Len(txt_qty.Text) Then
If (UCase$(txt_qty.Text) Like "[A-Z]" & String(Len(txt_qty.Text) - 1, "#")) Then
If UCase$(txt_qty.Text) <> txt_qty.Text Then
nSelStart = txt_qty.SelStart
nSelLen = txt_qty.SelLength
txt_qty.Text = UCase$(txt_qty.Text)
txt_qty.SelStart = nSelStart
txt_qty.SelLength = nSelLen
End If
txt_qty.BackColor = vbWindowBackground
Else
txt_qty.BackColor = mErrorColor
End If
Else
txt_qty.BackColor = vbWindowBackground
End If
End Sub
Private Sub txt_qty_KeyPress(KeyAscii As Integer)
Dim nSelLen As Long
nSelLen = txt_qty.SelLength
If txt_qty.SelStart = 0 And txt_qty.SelLength = 0 Then
'This will ensure that the first character is replaced if
'the user has moved the text caret to the beginning of the text
txt_qty.SelLength = 1
End If
KeyAscii = Asc(UCase$(Chr$(KeyAscii))) 'capitilize
Select Case KeyAscii
Case vbKeyBack
txt_qty.SelLength = nSelLen
Case vbKeyA To vbKeyZ
If txt_qty.SelStart <> 0 Then
KeyAscii = 0
txt_qty.SelLength = nSelLen
End If
Case vbKey0 To vbKey9
If txt_qty.SelStart = 0 Then
KeyAscii = 0
txt_qty.SelLength = nSelLen
End If
Case Else
KeyAscii = 0
txt_qty.SelLength = nSelLen
End Select
End Sub
Private Sub txt_qty_MouseDown(Button As Integer, Shift As Integer, X As Single, Y As Single)
If Not mnuContext Is Nothing Then
If Button And vbRightButton Then
'surpress the default context menu and show our custom menu instead
txt_qty.Enabled = False
txt_qty.Enabled = True
txt_qty.Parent.PopupMenu mnuContext
End If
End If
End Sub
then in my class(txtbox.cls):
VB Code:
Option Explicit
Private WithEvents txtbox As TextBox
Private mnuContext As Menu
Private mErrorColor As Long
Public Sub Init(TextBox As TextBox, _
Optional ErrorColor As Long = vbRed, _
Optional ContextMenu As Menu = Nothing)
Set mnuContext = ContextMenu
m_ErrorColor = ErrorColor
Set txtbox = TextBox
End Sub
Public Property Get ErrorColor() As Long
ErrorColor = mErrorColor
End Property
Public Property Let ErrorColor(nNew As Long)
mErrorColor = nNew
End Property
Public Property Set TextBox(txt As TextBox)
Set txtbox = txt
End Property
Public Property Get TextBox() As TextBox
Set TextBox = txtbox
End Property
Public Property Set ContextMenu(mnu As Menu)
Set mnuContext = mnu
End Property
Public Property Get ContextMenu() As Menu
Set ContextMenu = mnuContext
End Property
Private Sub Class_Initialize()
mErrorColor = vbRed
End Sub
This is what I did(where I pasted your codes..). Can you tell me why it still had errors?
Thank you so much. :blush:
-
Re: How to restrict users to enter first character as alphabet and rest as numeric.
This goes into frm_Field:
VB Code:
Option Explicit
Private oValidateText As CTextFormat
Private Sub Form_Load()
Set oValidateText = New CTextFormat
Set oValidateText.TextBox = Text1
Call oValidateText.Init(Text1, vbYellow, mnuPopUp)
End Sub
Now, just Add the Class to your project (the attached file from page 2)
Bruce.
-
Re: How to restrict users to enter first character as alphabet and rest as numeric.
Form code (one textbox called oValidateText is on it):
VB Code:
Option Explicit
Private oValidateText As CTextFormat
Private Sub Form_Load()
Set oValidateText = New CTextFormat
Set oValidateText.TextBox = Text1
Call oValidateText.Init(Text1, vbYellow, mnuPopUp)
End Sub
Class module code (class is called CTextFormat):
VB Code:
Option Explicit
Private WithEvents txtBox As TextBox
Private mnuContext As Menu
Private m_ErrorColor As Long
Public Sub Init(TextBox As TextBox, Optional ErrorColor As Long = vbRed, Optional ContextMenu As Menu = Nothing)
Set mnuContext = ContextMenu
m_ErrorColor = ErrorColor
Set txtBox = TextBox
End Sub
Public Property Get ErrorColor() As Long
ErrorColor = m_ErrorColor
End Property
Public Property Let ErrorColor(nNew As Long)
m_ErrorColor = nNew
End Property
Public Property Set TextBox(txt As TextBox)
Set txtBox = txt
End Property
Public Property Get TextBox() As TextBox
Set txtBox = txtBox
End Property
Public Property Set ContextMenu(mnu As Menu)
Set mnuContext = mnu
End Property
Public Property Get ContextMenu() As Menu
Set ContextMenu = mnuContext
End Property
Private Sub Class_Initialize()
m_ErrorColor = vbRed
End Sub
Private Sub txtBox_Change()
Dim nSelStart As Long, nSelLen As Long
If Len(txtBox.Text) Then
If (UCase$(txtBox.Text) Like "[A-Z]" & String(Len(txtBox.Text) - 1, "#")) Then
If UCase$(txtBox.Text) <> txtBox.Text Then
nSelStart = txtBox.SelStart
nSelLen = txtBox.SelLength
txtBox.Text = UCase$(txtBox.Text)
txtBox.SelStart = nSelStart
txtBox.SelLength = nSelLen
End If
txtBox.BackColor = vbWindowBackground
Else
txtBox.BackColor = m_ErrorColor
End If
Else
txtBox.BackColor = vbWindowBackground
End If
End Sub
Private Sub txtBox_KeyPress(KeyAscii As Integer)
Dim nSelLen As Long
nSelLen = txtBox.SelLength
If txtBox.SelStart = 0 And txtBox.SelLength = 0 Then
'This will ensure that the first character is replaced if
'the user has moved the text caret to the beginning of the text
txtBox.SelLength = 1
End If
KeyAscii = Asc(UCase$(Chr$(KeyAscii))) 'capitilize
Select Case KeyAscii
Case vbKeyBack
txtBox.SelLength = nSelLen
Case vbKeyA To vbKeyZ
If txtBox.SelStart <> 0 Then
KeyAscii = 0
txtBox.SelLength = nSelLen
Else
KeyAscii = Asc(UCase$(Chr$(KeyAscii))) 'capitilize
End If
Case vbKey0 To vbKey9
If txtBox.SelStart = 0 Then
KeyAscii = 0
txtBox.SelLength = nSelLen
End If
Case Else
KeyAscii = 0
txtBox.SelLength = nSelLen
End Select
End Sub
Private Sub txtBox_MouseDown(Button As Integer, Shift As Integer, X As Single, Y As Single)
If Not mnuContext Is Nothing Then
If Button And vbRightButton Then
'surpress the default context menu and show our custom menu instead
txtBox.Enabled = False
txtBox.Enabled = True
txtBox.Parent.PopupMenu mnuContext
End If
End If
End Sub
-
Re: How to restrict users to enter first character as alphabet and rest as numeric.
VB Code:
Public MyChar
Function validity()
If Len(Text1.Text) = 1 Then
If InStr(MyChar, Left(Text1.Text, 1)) = 0 Then
'KeyAscii = 0
MsgBox "Invalid format"
Exit Function
End If
Exit Function
End If
On Error GoTo kulitag
If Not IsNumeric(Right(Text1.Text, Len(Text1.Text) - 1)) Then
MsgBox "Invalid format"
KeyAscii = 0
End If
kulitag:
End Function
Private Sub Form_Load()
MyChar = "ABCDEFGHIJKLMNOPQRSTUVWXYZabcdefghijklmnopqrstuvwxyz"
End Sub
Private Sub Text1_Change()
validity
End Sub
just wnt to try! :afrog:
-
Re: How to restrict users to enter first character as alphabet and rest as numeric.
Ugghhh... I think I'll just use the code of Bruce Fox instead of using this method, w/c uses class....it just isn't working (maybe it's my fault...I'm just a newbie)....
Thank you so much Baja for answering my questions.. =)
-
Re: How to restrict users to enter first character as alphabet and rest as numeric.
ei sera have you tried mine?
-
Re: How to restrict users to enter first character as alphabet and rest as numeric.
Quote:
Originally Posted by seraphicmortal
Ugghhh... ....it just isn't working (maybe it's my fault...I'm just a newbie)....
:) Persist with it it's worth it.
Start a new Project, in Form1 place the code identified, and 'Add' a Class Module and paste that code in (ensure the Class Module name is cTextFormat, now add a TextBox.
Thats it :)
Edit: Rem out: "Call oValidateText.Init(Text1, vbYellow, mnuPopUp)" just to test it (as you wount have the Menu).
Bruce.
-
Re: How to restrict users to enter first character as alphabet and rest as numeric.
ooki dokie...will do as told Bruce! ;) As for Kulitag, I think there's a bit error. Thanks for trying anyways.
-
Re: How to restrict users to enter first character as alphabet and rest as numeric.
Quote:
Originally posted by Bruce Fox
Edit: Rem out: "Call oValidateText.Init(Text1, vbYellow, mnuPopUp)" just to test it (as you wount have the Menu).
Just did what you and Baja said.
The ones in red is the one having error....same thing happened when I pasted it in my program and when I made a new project.
mnuPopUp is variable not defined.
:confused:
-
Re: How to restrict users to enter first character as alphabet and rest as numeric.
Quote:
Originally Posted by seraphicmortal
Just did what you and Baja said.
The ones in red is the one having error....same thing happened when I pasted it in my program and when I made a new project.
mnuPopUp is variable not defined.
:confused:
mnuPopUp would be a menu item that you want to have 'popup' when the user clicks(or right-click) an item on your form.
Check the VB help files for 'PopupMenu'
-
2 Attachment(s)
Re: How to restrict users to enter first character as alphabet and rest as numeric.
Quote:
Originally Posted by seraphicmortal
Just did what you and Baja said.
The ones in red is the one having error....same thing happened when I pasted it in my program and when I made a new project.
mnuPopUp is variable not defined.
:confused:
To be able to assign a menu you have to create one. Start the menu editor and create a menu call mnuPopUp and create some sub menu items. Look at the attached Form for an example. If you don't want to assign a custom popup menu just call it like this instead:
VB Code:
Call oValidateText.Init(Text1)
Or you could use this code which does the same thing.
VB Code:
Set oValidateText.TextBox = Text1
Since you for some reason couldn't download ZIP files I've attached a form and the class. Create a new project and remove the empty form that is created. Now add this form and class instead.
-
Re: How to restrict users to enter first character as alphabet and rest as numeric.
cvmicheal has embarrassed me to no end... thx cv as this one liner has saved me carpel tunnel.
can i retract my reply?
-
Re: How to restrict users to enter first character as alphabet and rest as numeric.
-
Re: How to restrict users to enter first character as alphabet and rest as numeric.
Finally, I got what Joacim's idea.... :blush: Thank you so much. :wave: Yah, I agree with Bruce his codes really is so worth it.. :) Thank you...Thank you...Thank you! :thumb:
-
Re: How to restrict users to enter first character as alphabet and rest as numeric.
In that case you are (finally) welcome :)