Results 1 to 7 of 7
  1. #1
    slimjen is offline Expert
    Windows XP Access 2007
    Join Date
    Mar 2010
    Posts
    727

    validation


    All using ms access 2003. I have a input form in one of my database that has a calculated field to balance two other fields on the form. How can I prevent the user from going to the next record or exiting when the field does not balance? Ex. Total charges=$300 Invoice Total = $297.00. Balance=$3.00
    Code:
    =sum([totalcharges]-[invoicetotal])
    Balance should always = $0.
    The users should not be able to precede if the balance is not $0.
    Thanks

  2. #2
    NoellaG's Avatar
    NoellaG is offline VIP
    Windows 7 Access 2010 (version 14.0)
    Join Date
    Jun 2010
    Location
    Belgium
    Posts
    1,044
    Hi,

    you can write a test in the beforeupdate event of the form.

    greeting
    NG

  3. #3
    slimjen is offline Expert
    Windows XP Access 2007
    Join Date
    Mar 2010
    Posts
    727
    ? how?. something like if isnot[balance] = <>0
    Just giving a shot in the dark. I have no idea how to write this.

  4. #4
    NoellaG's Avatar
    NoellaG is offline VIP
    Windows 7 Access 2010 (version 14.0)
    Join Date
    Jun 2010
    Location
    Belgium
    Posts
    1,044
    Hi,

    try something according the following style:

    Code:
    Private Sub Form_BeforeUpdate(Cancel As Integer)
    On Error GoTo Err_Form_BeforeUpdate
    
        If a <> b Then
            Cancel = True
            Me.Undo
            MsgBox "a must be equel to 2"
        End If
    
    Exit_Form_BeforeUpdate
        Exit Sub
        
    Err_Form_BeforeUpdate:
        MsgBox Err.Number & ": " & Err.Description
        Resume Exit_Form_BeforeUpdate
    
    End Sub
    greetings
    NG

  5. #5
    slimjen is offline Expert
    Windows XP Access 2007
    Join Date
    Mar 2010
    Posts
    727
    I tried this code. It's not working. I am not getting a msg before or after moving to the next record or exiting the form. What am I doing wrong. Thanks
    Code:
     
    Private Sub BALANCE_BeforeUpdate(Cancel As Integer)
    On Error GoTo Err_BALANCE_BeforeUpdate
        If Me.BALANCE <> 0 Then
            Cancel = True
            Me.Undo
            MsgBox "Balance must be equal to 0"
        End If
    Exit_BALANCE_BeforeUpdate:
        Exit Sub
        
    Err_BALANCE_BeforeUpdate:
        MsgBox Err.Number & ": " & Err.Description
        Resume Exit_BALANCE_BeforeUpdate
    End Sub

  6. #6
    NoellaG's Avatar
    NoellaG is offline VIP
    Windows 7 Access 2010 (version 14.0)
    Join Date
    Jun 2010
    Location
    Belgium
    Posts
    1,044
    Hi,

    it's the place you have put the code: you have put it in the before-update event of the control "BALANCE", you should put it in the beforeupdate event of the form itself

    greetings
    NG

  7. #7
    slimjen is offline Expert
    Windows XP Access 2007
    Join Date
    Mar 2010
    Posts
    727
    Hi, I am putting this in the balance before update of a subform. I also tried it on the main form and it still doesnt work. I need to put a save button on the form anyway; should I try on the save button to code?
    Thanks

Please reply to this thread with any new information or opinions.

Similar Threads

  1. Validation Rule
    By ritzzy in forum Access
    Replies: 1
    Last Post: 04-13-2011, 01:33 PM
  2. Validation Question
    By ksmithson in forum Forms
    Replies: 1
    Last Post: 07-15-2010, 03:02 PM
  3. Validation Rule
    By robomose in forum Access
    Replies: 1
    Last Post: 09-09-2009, 05:59 AM
  4. Validation Rule
    By smitstev in forum Access
    Replies: 5
    Last Post: 06-30-2009, 09:58 AM
  5. Validation problems...
    By dbDamo in forum Forms
    Replies: 1
    Last Post: 05-15-2009, 12:43 PM

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts
  •  
Other Forums: Microsoft Office Forums