1. Computer problem? Tech Support Guy is completely free -- paid for by advertisers and donations. Click here to join today! If you're new to Tech Support Guy, we highly recommend that you visit our Guide for New Members.

Access 2007 Compare subform total with field on main form

Discussion in 'Business Applications' started by Access07Question, Jul 5, 2011.

Thread Status:
Not open for further replies.
Advertisement
  1. Access07Question

    Access07Question Thread Starter

    Joined:
    Jul 5, 2011
    Messages:
    5
    Hi, I would like to display a message box when a total on a subform does not match a field in the main form.

    I have a form (FormA) with a subform (SubformA)

    I need to compare the total on subformA (located on SubForm A footer) with a field on FormA

    I am entering a number on the subform and in the On Exit Event I entered me.requery to requery the data and update the total in the footer - then I entered the code to compare the two numbers

    This is the code I am using (edited):

    me.requery
    If [FormA field] <> [SubformA total] Then
    Msgbox ("Amounts Do Not Equal")
    End IF

    The problem I am having is the refresh time of subformA footer - the field takes longer to refresh or requery (I tried both) and the message box displays even when the numbers are equal

    Thanks in advance
     
  2. Ziggy1

    Ziggy1

    Joined:
    Jun 17, 2002
    Messages:
    2,551
    try this, I'm just going by memory. I also assigned the references to variables as it looks cleaner


    Code:
    dim mainF, SubF as string
    
    MainF = forms!formA.field
    
    SubF = Forms![formA]![subformA].Form!total
    
    
    me.requery
    If  MainF  <> SubF Then
    Msgbox ("Amounts Do Not Equal")
    End IF
    
    
     
  3. Access07Question

    Access07Question Thread Starter

    Joined:
    Jul 5, 2011
    Messages:
    5
    Thanks for the quick reply - the code to compare the two fields still runs before the total in the subform refreshes - the db will be moved to a SQL server in another week or two - so I'm wondering if your code does work but I'm now dealing with a time delay between my workstation and the server - Thanks for your help!
     
  4. Ziggy1

    Ziggy1

    Joined:
    Jun 17, 2002
    Messages:
    2,551
    you will have to add a "requery" to the form control first then
     
  5. Access07Question

    Access07Question Thread Starter

    Joined:
    Jul 5, 2011
    Messages:
    5
    I was finally able to get this to work by using Me.Recalc instead of requery - Thanks again for your help!
     
  6. Sponsor

As Seen On
As Seen On...

Welcome to Tech Support Guy!

Are you looking for the solution to your computer problem? Join our site today to ask your question. This site is completely free -- paid for by advertisers and donations.

If you're not already familiar with forums, watch our Welcome Guide to get started.

Join over 733,556 other people just like you!

Loading...
Thread Status:
Not open for further replies.

Short URL to this thread: https://techguy.org/1005837

  1. This site uses cookies to help personalise content, tailor your experience and to keep you logged in if you register.
    By continuing to use this site, you are consenting to our use of cookies.
    Dismiss Notice