Trapping for decimal values in an integer field

  • I'm working on some code in Access 2003 that is strictly a front-end form for a SQL Server 2005 database. The only field in the form is an integer. My boss wants me to throw an error if someone tries to enter a decimal value.

    I tried this approach but it doesn't work:

    [font="Courier New"]Private Sub VoteCount_BeforeUpdate(Cancel As Integer)

    Dim x As Integer

    If VoteCount.Value <> Int(VoteCount.Value) Then

    x = MsgBox("No decimals allowed! Enter integers only!", vbSystemModal, "ERROR")

    VoteCount.SetFocus

    End If

    End Sub[/font]

    My skills in VB/Access are very rusty, I have a feeling that I'm missing something simple. I don't think I want to use the AfterUpdate event as the strange data would already be written to the DB in truncated format.

    Any ideas?

    -----
    [font="Arial"]Knowledge is of two kinds. We know a subject ourselves or we know where we can find information upon it. --Samuel Johnson[/font]

  • I think you can set the front end field property to accept 0 decimals. :hehe:

    This way it will not allow decimals.

    Johan

    Learn to play, play to learn !

    Dont drive faster than your guardian angel can fly ...
    but keeping both feet on the ground wont get you anywhere :w00t:

    - How to post Performance Problems
    - How to post data/code to get the best help[/url]

    - How to prevent a sore throat after hours of presenting ppt

    press F1 for solution, press shift+F1 for urgent solution 😀

    Need a bit of Powershell? How about this

    Who am I ? Sometimes this is me but most of the time this is me

  • Sadly, that won't work. Yes, it does work, but I have to allow the erroneous input and then pop up an error. Thus, I'm trying to trap the value to pop up an error box.

    -----
    [font="Arial"]Knowledge is of two kinds. We know a subject ourselves or we know where we can find information upon it. --Samuel Johnson[/font]

  • Try this.

    [font="Courier New"]Private Sub VoteCount_BeforeUpdate(Cancel As Integer)

    Dim x As Integer

    If VoteCount.Value <> Int(VoteCount.Value) Then

    x = MsgBox("No decimals allowed! Enter integers only!", vbSystemModal, "ERROR")

    VoteCount.SetFocus

    Cancel = True

    End If

    End Sub[/font]

Viewing 4 posts - 1 through 3 (of 3 total)

You must be logged in to reply to this topic. Login to reply