enter blank

  • Thread starter Thread starter adriany
  • Start date Start date
A

adriany

looks like my txtbox accepts null(blank data).

how do i make it so only accepts input data that are
numbers only not letter(text).

i don't want table field to be number
 
To prevent the field being left blank, open the table in design view, select
the field, and set these properties:
Required Yes
Allow Zero Length No

You could set up an Input Mask so the field accepts numbers only.
Alternatively, if you enter data through a form, you could set the text
box's On Key Down property to [Event Procedure], and use the following
procedure to prevent the user entering anything except digits or backspace:


Sub DigitOnly(KeyAscii As Integer)
'Purpose: Disallow any keystroke except 0 ~ 9, and backspace.
'Usage: In a text box's KeyDown event procedure:
' Call DigitOnly(KeyAscii)

If KeyAscii < 48 Or KeyAscii > 57 Then
If KeyAscii <> vbKeyBack Then
KeyAscii = 0
End If
End If
End Sub
 
I use a Select Case instead, function is the same however:

Select Case KeyAscii(KeyAscii as Integer)
Case 48 to 57 'numbers 0 through 9
Case 8 'allows backspace
Case Else
KeyAscii = 0
End Select

You could always add a Beep or something as well, if you want to inform the
user that their keystrokes are no good.
You can add more this way as well into the future (say you decide to add
hyphens in, or just the letter 'A' or...whatever...)
Instead of nesting more in the If/Then, you just add the case to the
group, recompile and you're done.

HTH,
Gary

Allen Browne said:
To prevent the field being left blank, open the table in design view, select
the field, and set these properties:
Required Yes
Allow Zero Length No

You could set up an Input Mask so the field accepts numbers only.
Alternatively, if you enter data through a form, you could set the text
box's On Key Down property to [Event Procedure], and use the following
procedure to prevent the user entering anything except digits or backspace:


Sub DigitOnly(KeyAscii As Integer)
'Purpose: Disallow any keystroke except 0 ~ 9, and backspace.
'Usage: In a text box's KeyDown event procedure:
' Call DigitOnly(KeyAscii)

If KeyAscii < 48 Or KeyAscii > 57 Then
If KeyAscii <> vbKeyBack Then
KeyAscii = 0
End If
End If
End Sub

--
Allen Browne - Microsoft MVP. Perth, Western Australia.

Reply to group, rather than allenbrowne at mvps dot org.

adriany said:
looks like my txtbox accepts null(blank data).

how do i make it so only accepts input data that are
numbers only not letter(text).

i don't want table field to be number
 
i guessing i should included on event before update at
txtbox?

-----Original Message-----
I use a Select Case instead, function is the same however:

Select Case KeyAscii(KeyAscii as Integer)
Case 48 to 57 'numbers 0 through 9
Case 8 'allows backspace
Case Else
KeyAscii = 0
End Select

You could always add a Beep or something as well, if you want to inform the
user that their keystrokes are no good.
You can add more this way as well into the future (say you decide to add
hyphens in, or just the letter 'A' or...whatever...)
Instead of nesting more in the If/Then, you just add the case to the
group, recompile and you're done.

HTH,
Gary

To prevent the field being left blank, open the table
in design view,
select
the field, and set these properties:
Required Yes
Allow Zero Length No

You could set up an Input Mask so the field accepts numbers only.
Alternatively, if you enter data through a form, you could set the text
box's On Key Down property to [Event Procedure], and use the following
procedure to prevent the user entering anything except
digits or
backspace:
Sub DigitOnly(KeyAscii As Integer)
'Purpose: Disallow any keystroke except 0 ~ 9, and backspace.
'Usage: In a text box's KeyDown event procedure:
' Call DigitOnly(KeyAscii)

If KeyAscii < 48 Or KeyAscii > 57 Then
If KeyAscii <> vbKeyBack Then
KeyAscii = 0
End If
End If
End Sub


.
 
gary,

how do i use select case to work! never used before?
-----Original Message-----
i guessing i should included on event before update at
txtbox?

-----Original Message-----
I use a Select Case instead, function is the same however:

Select Case KeyAscii(KeyAscii as Integer)
Case 48 to 57 'numbers 0 through 9
Case 8 'allows backspace
Case Else
KeyAscii = 0
End Select

You could always add a Beep or something as well, if
you
want to inform the
user that their keystrokes are no good.
You can add more this way as well into the future (say you decide to add
hyphens in, or just the letter 'A' or...whatever...)
Instead of nesting more in the If/Then, you just
add
the case to the
group, recompile and you're done.

HTH,
Gary

To prevent the field being left blank, open the table
in design view,
select
the field, and set these properties:
Required Yes
Allow Zero Length No

You could set up an Input Mask so the field accepts numbers only.
Alternatively, if you enter data through a form, you could set the text
box's On Key Down property to [Event Procedure], and use the following
procedure to prevent the user entering anything
except
digits or
backspace:


.
.
 
put it in the VBA code for the txtbox's KeyPress event

Like this:
---
Private Sub txtHours_KeyPress(KeyAscii As Integer)

Select Case KeyAscii
Case 48 To 57, 8
Case Else
KeyAscii = 0
End Select

End Sub
---
(BTW- 8 is the ASCII designation of the backspace key)

HTH - Gary
adriany said:
gary,

how do i use select case to work! never used before?
-----Original Message-----
i guessing i should included on event before update at
txtbox?

-----Original Message-----
I use a Select Case instead, function is the same however:

Select Case KeyAscii(KeyAscii as Integer)
Case 48 to 57 'numbers 0 through 9
Case 8 'allows backspace
Case Else
KeyAscii = 0
End Select

You could always add a Beep or something as well, if
you
want to inform the
user that their keystrokes are no good.
You can add more this way as well into the future (say you decide to add
hyphens in, or just the letter 'A' or...whatever...)
Instead of nesting more in the If/Then, you just
add
the case to the
group, recompile and you're done.

HTH,
Gary

To prevent the field being left blank, open the table in design view,
select
the field, and set these properties:
Required Yes
Allow Zero Length No

You could set up an Input Mask so the field accepts numbers only.
Alternatively, if you enter data through a form, you could set the text
box's On Key Down property to [Event Procedure], and use the following
procedure to prevent the user entering anything
except
digits or
backspace:


Sub DigitOnly(KeyAscii As Integer)
'Purpose: Disallow any keystroke except 0 ~ 9, and backspace.
'Usage: In a text box's KeyDown event procedure:
' Call DigitOnly(KeyAscii)

If KeyAscii < 48 Or KeyAscii > 57 Then
If KeyAscii <> vbKeyBack Then
KeyAscii = 0
End If
End If
End Sub

--
Allen Browne - Microsoft MVP. Perth, Western Australia.
Tips for Access users - http://allenbrowne.com/tips.html
Reply to group, rather than allenbrowne at mvps dot org.

looks like my txtbox accepts null(blank data).

how do i make it so only accepts input data that are
numbers only not letter(text).

i don't want table field to be number




.
.
 
Back
Top