I have a text box that I only want a user to be able to enter integers. I have it so that if a number with a decmail place is enter a error message comes up. But when i was testing the code, I entered a letter in and i got a runtime error.. I was wondeirng what I would use give an error if a letter what typed in.
7 3850
you need to check the ascii value of integers and handle the same in key press event.
dear,
I hope this will help - Private Sub Text1_Change()
-
With Text1
-
'§ check for letters
-
If Not IsNumeric(.Text) And (.Text) <> "" Then
-
MsgBox ("Enter a NUMBER !")
-
Else
-
'§ check for DOT or COMMA
-
If InStr(.Text, ".") Or InStr(.Text, ",") Then
-
MsgBox ("Enter an INTEGER value !")
-
Else
-
'§ enter your code....
-
' MsgBox ("This is OK")
-
End If
-
End If
-
End With
-
End Sub
br,
How that restricts the entry of characters ?
dear,
The "If Not IsNumeric(.Text) ..." checks if the string in text1 is a value.
From the moment you type a character, it gives a textbox with a warning.
Just try it.(see attachment)
Notice: I have also entered 2 commands which delete the last wrong character and sets the cursor to the last position.
br,
- Private Sub txtBoxName_Change()
-
With txtBoxName
-
'§ check for letters
-
If Not IsNumeric(.Text) And (.Text) <> "" Then
-
MsgBox ("Enter a NUMBER !")
-
'§ clear the last character
-
.Text = Left(.Text, Len(.Text) - 1)
-
'§ set the cursor at the end of the string
-
.SelStart = Len(.Text)
-
Else
-
'§ check for DOT or COMMA
-
If InStr(.Text, ".") Or InStr(.Text, ",") Then
-
MsgBox ("Enter an INTEGER value !")
-
Else
-
'§ enter your code....
-
' MsgBox ("This is OK")
-
End If
-
End If
-
End With
-
End Sub
This piece of code does exactly the work. But I would like to have a Windows Sound rather than a message box. Is it possible?
'I found it from another source
'Copy the following and paste it in frm module (in declatrations division) of your project where you want the sound to be played - Private Declare Function MessageBeep Lib "user32" _
-
(ByVal wType As Long) As Long
-
Private Const MB_ICONASTERISK = &H40&
-
Private Const MB_ICONEXCLAMATION = &H30&
-
Private Const MB_ICONHAND = &H10&
-
Private Const MB_ICONINFORMATION = MB_ICONASTERISK
-
Private Const MB_ICONMASK = &HF0&
-
Private Const MB_ICONQUESTION = &H20&
-
Private Const MB_ICONSTOP = MB_ICONHAND
-
-
-
-
-
-
-
'Copy the following and paste it in the textbox_change() module
-
-
-
Private Sub txtBoxName_Change()
-
-
With txtDate1
-
'§ check for letters
-
If Not IsNumeric(.Text) And (.Text) <> "" Then
-
Call MessageBeep(MB_ICONINFORMATION)
-
-
'§ clear the last character
-
.Text = Left(.Text, Len(.Text) - 1)
-
'§ set the cursor at the end of the string
-
.SelStart = Len(.Text)
-
Else
-
'§ check for DOT or COMMA and OTHERS
-
If InStr(.Text, ",") Or InStr(.Text, "$") Or InStr(.Text, "-") Or InStr(.Text, "+") Or InStr(.Text, "\") Or InStr(.Text, "*") Then
-
-
-
Call MessageBeep(MB_ICONINFORMATION)
-
-
.Text = Left(.Text, Len(.Text) - 1)
-
Else
-
'§ enter your code....
-
' MsgBox ("This is OK")
-
End If
-
End If
-
End With
-
End Sub
Sign in to post your reply or Sign up for a free account.
Similar topics
by: Renie83 |
last post by:
Hi I really am going crazy!
I'm using VBScript, ASP, and SQL
My page reminds me of a shopping cart but looking at shopping cart
examples has not helped!
What I have is a page that brings in...
|
by: Stuart |
last post by:
This is probably a frequent question, but I can't find the answer
anywhere.
I'm developing a search page for a form, and since the results change
with each keypress, I need to allow spaces (ie...
|
by: Cro |
last post by:
Dear Access Developers,
The 'Allow Additions' property of my form is causing unexpected
results.
I am developing a form that has its 'Default View' property set to
'Continuous Forms' and am...
|
by: antonyliu2002 |
last post by:
The full code is pasted below. It looks scarily long, but it's pretty
simple. It is adapted from a sample code at MSDN.
If you run it, and check it out from your browser, you'll see:
...
|
by: Kermit Piper |
last post by:
Hello,
I have a function that lets me convert one character and throw an alert
with the corresponding ASCII value, but what I am having trouble with
is applying it to a text box. What I'm trying...
|
by: rickn |
last post by:
Being new to VB and programming, I'm not sure how to modify the
following or if required have a Select statement to NOT allow any
duplicates. I'm trying not to have any duplicates in the LOTNUM_72...
|
by: cameron |
last post by:
I am working on an assignment where I have to allow end-users to enter in data and to have C++ make a calculation. From there I have to set up a loop to allow users to go back and enter new data or...
|
by: acecraig100 |
last post by:
I am fairly new to Javascript. I have a form that users fill out to
enter an animal to exhibit at a fair. Because we have no way of
knowing, how many animals a user may enter, I created a table...
|
by: Steve |
last post by:
Hi guys,
I am working on a Team Process Template for TFS 2008. I have created
my own work item type, which has (amongst other controls) a HTML
control to hold process guidance text:
<FIELD...
|
by: taylorcarr |
last post by:
A Canon printer is a smart device known for being advanced, efficient, and reliable. It is designed for home, office, and hybrid workspace use and can also be used for a variety of purposes. However,...
|
by: aa123db |
last post by:
Variable and constants
Use var or let for variables and const fror constants.
Var foo ='bar';
Let foo ='bar';const baz ='bar';
Functions
function $name$ ($parameters$) {
}
...
|
by: ryjfgjl |
last post by:
In our work, we often receive Excel tables with data in the same format. If we want to analyze these data, it can be difficult to analyze them because the data is spread across multiple Excel files...
|
by: emmanuelkatto |
last post by:
Hi All, I am Emmanuel katto from Uganda. I want to ask what challenges you've faced while migrating a website to cloud.
Please let me know.
Thanks!
Emmanuel
|
by: nemocccc |
last post by:
hello, everyone, I want to develop a software for my android phone for daily needs, any suggestions?
|
by: Sonnysonu |
last post by:
This is the data of csv file
1 2 3
1 2 3
1 2 3
1 2 3
2 3
2 3
3
the lengths should be different i have to store the data by column-wise with in the specific length.
suppose the i have to...
|
by: Hystou |
last post by:
There are some requirements for setting up RAID:
1. The motherboard and BIOS support RAID configuration.
2. The motherboard has 2 or more available SATA protocol SSD/HDD slots (including MSATA, M.2...
|
by: marktang |
last post by:
ONU (Optical Network Unit) is one of the key components for providing high-speed Internet services. Its primary function is to act as an endpoint device located at the user's premises. However,...
|
by: jinu1996 |
last post by:
In today's digital age, having a compelling online presence is paramount for businesses aiming to thrive in a competitive landscape. At the heart of this digital strategy lies an intricately woven...
| |