Dont Want a Decimal Value in Field.

  • Thread starter Malik via AccessMonster.com
  • Start date
M

Malik via AccessMonster.com

Hi.
I want that if a user enters a Decimal Value in a field, the form or table
should not accept it and Run a MsgBox.

Thanks
 
L

Linq Adams via AccessMonster.com

Is this textbox bound to a Numeric field in the underlying table? If so, you
could define it as an Integer, and Access would simply lop off any decimals
the user added. If that doesn't work for you, you could check for the Decimal
Point:

Private Sub YourTextBox_BeforeUpdate(Cancel As Integer)
If InStr(Me.YourTextBox, ".") > 0 Then
MsgBox "Decimals Are Not Allowed!"
Cancel = True
Me.YourTextBox.SelStart = 0
Me.YourTextBox.SelLength = Len(Me.YourTextBox)
End If
End Sub
 
M

malik via AccessMonster.com

Linq said:
Is this textbox bound to a Numeric field in the underlying table? If so, you
could define it as an Integer, and Access would simply lop off any decimals
the user added. If that doesn't work for you, you could check for the Decimal
Point:

Private Sub YourTextBox_BeforeUpdate(Cancel As Integer)
If InStr(Me.YourTextBox, ".") > 0 Then
MsgBox "Decimals Are Not Allowed!"
Cancel = True

This is not working. It is not giving any error but not working as well.

Thanks
 
L

Linq Adams via AccessMonster.com

Let's see the exact code you've tried. Also, what datatype is the underlying
field for the textbox?
 

Ask a Question

Want to reply to this thread or ask your own question?

You'll need to choose a username for the site, which only take a couple of moments. After that, you can post your question and our members will help you out.

Ask a Question

Top