Results 1 to 5 of 5
  1. #1
    foureyes is offline Novice
    Windows XP Access 2003
    Join Date
    Jul 2009
    Location
    Sydney, Australia
    Posts
    2

    Unhappy Subform calculations

    Hi



    I am new to VBA and have spent all day trying to get this sorted so appreciate any help!!

    I have a sub form that lists the percentage of the sale that belongs to each salesperson. So in may cases one sales person will make 100% of the sale, but sometimes its split across 2 for example, 50% each. The field that keeps this data in called "Split". I also have a total in my footer that sums all "Split". When my footer total doesn't add upto 100% I want a msg box to appear advising the user.

    Problem is that I can seem to get access to run the footer calc quick enough. So, if the user enters in error 150% and then tabs to a new record it’s allowed because it hasn't calculated the total by the time it creates a new record. If however, the user tries for a third record it will bring up the msg box as the 1st record is still over 100%.

    I have tried various things, hoping that someone out there has come across this before and has a solution. Thanks in advance!!

  2. #2
    RuralGuy's Avatar
    RuralGuy is offline Administrator
    Windows 10 Access 2013 32bit
    Join Date
    Mar 2007
    Location
    8300' in the Colorado Rocky Mountains
    Posts
    12,922
    The "sum" in the footer can not update until the record you are working on is saved. That happens when you move to a new record. That should give you a puzzle to think about for a bit.

  3. #3
    tlittell is offline Novice
    Windows XP Access 2003
    Join Date
    Jul 2009
    Location
    Pittsburgh, PA
    Posts
    8
    The data validation you describe doesn't sound complicated and should run quickly. In what event (form1_beforeupdate, text1_change, etc) did you code your validation check? Could make a difference. Include your code if you can.

  4. #4
    foureyes is offline Novice
    Windows XP Access 2003
    Join Date
    Jul 2009
    Location
    Sydney, Australia
    Posts
    2

    Smile

    Thanks for your help!!

    I have done the addition now in my code and that seems to calculate it instantly and then it displays an error message.

    My next problem is after the error message has been OK'd I want the cursor to move to the previous field but when I say Me.recordset.moveprevious it doesn't seem to work.. don't suppose you know why this maybe? I have pasted my code below:-

    Code:
    Private Sub Placement_Split_AfterUpdate()
    Dim dSplitCntr As Double
    Me
    .testbox1.Requery     'testbox is just so that i can see in the form whether the calc is working

    Forms!Fm_SubForm.Recordset.MoveFirst
        
    Do While Not Forms!Fm_SubForm.Recordset.EOF
        For Each Item In Forms!Fm_SubForm.Controls
           If Item.Name = "Placement Split" Then
               dSplitCntr = dSplitCntr + Item.Value
           End If
           
        Next
        Forms!Fm_SubForm.Recordset.MoveNext
    Loop
    Me.testbox1.Requery

    Forms!Fm_SubForm!testbox1 = dSplitCntr
    If dSplitCntr > 1 Then
    Response = MsgBox("Error", vbOKOnly)
            Me.Recordset.MovePrevious 
    thanks!

  5. #5
    tlittell is offline Novice
    Windows XP Access 2003
    Join Date
    Jul 2009
    Location
    Pittsburgh, PA
    Posts
    8
    Do you get an error when it tries to .moveprevious or just nothing happens? Remember there has to be a valid record for it to move to, so if you're testing your error handling on the 1st record then there's nothing to moveprevious to.

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

Similar Threads

  1. Subform and calculations issues
    By rustyCrVx in forum Access
    Replies: 1
    Last Post: 05-02-2009, 03:37 PM
  2. Time calculations
    By jimandann in forum Programming
    Replies: 2
    Last Post: 02-18-2009, 12:27 AM
  3. Calculations in linked forms
    By Dena Grabinar in forum Forms
    Replies: 0
    Last Post: 08-22-2008, 05:34 AM
  4. Replies: 1
    Last Post: 12-10-2005, 04:52 PM
  5. Subform in a Subform and relationships
    By St3ph3n in forum Database Design
    Replies: 3
    Last Post: 12-06-2005, 06:34 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