Results 1 to 4 of 4
  1. #1
    Benj is offline Advanced Beginner
    Windows 7 32bit Access 2016
    Join Date
    May 2018
    Posts
    33

    main form and child form total

    i added an if statement to the NEXT and NEW record buttons in the main form. It goes to the next or new record if




    main form - subform = zero (mainform minus subformTOTAL is equal to zero)


    if not, it will message you to recheck your data. it does what its supposed to do if the current record in the subform has values, but if you happen to click to a new record in the subform (inadvernetly) without entering anything it would consider the subform as null, therefore it would not go to the new record.


    Dim ANSWE As String
    If Me.grandTOT = 0 Then
    DoCmd.GoToRecord , , acNewRec


    Else
    ANSWE = MsgBox("TOTAL DOESN'T ADD TO 0, IGNORE?", vbYesNo, "LITTER BALANCE")
    If ANSWE = vbYes Then
    DoCmd.GoToRecord , , acNewRec

    Else
    Exit Sub
    End If
    End If


    End Sub




    grandTOT is Nz([BornAlive])-Nz([WeanNumber])-Nz([SplitNumber])+Nz([piglet].[Form]![Text44]))


    text44 is =DSum("ptot","qrypiglet","SowIds = '" & [SowIds] & "'")


    ptot is IIf(IsNull([Reason]=True),[PigNum],[PigNum]*-1)


    I hope it makes sense. Thanks in advance!

  2. #2
    AccessToGo is offline Novice
    Windows 10 Access 2007
    Join Date
    May 2018
    Location
    UK
    Posts
    15
    Hi Benj, Ok, in your subform, when you click in a new record everything is null including [SowIds] therefore text44 will be null even though there are other records in the subform.
    Try changing to...
    text44 is =DSum("ptot","qrypiglet","SowIds = '" & Me.[Parent]![whatever SowId is In Main Form] & "'")
    Regards
    Chris

  3. #3
    Benj is offline Advanced Beginner
    Windows 7 32bit Access 2016
    Join Date
    May 2018
    Posts
    33
    i did text44 =DSum("ptot","qrypiglet","SowIds = '" & [Me].[Main]![SowID] & "'") but its giving me #Name? (Text44). thanks again!

  4. #4
    AccessToGo is offline Novice
    Windows 10 Access 2007
    Join Date
    May 2018
    Location
    UK
    Posts
    15
    Oh no, use the word Parent not the name of the form. Parent is a vba reserved word to reference the containing object. In fact I don't think the Me should be there so
    try [Parent]![SowID]

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

Similar Threads

  1. Replies: 1
    Last Post: 04-06-2017, 11:28 AM
  2. Replies: 3
    Last Post: 04-06-2017, 10:40 AM
  3. Subform total on main form
    By muhammadirfanghori in forum Forms
    Replies: 1
    Last Post: 03-12-2015, 08:42 AM
  4. Replies: 19
    Last Post: 06-30-2014, 04:36 PM
  5. Replies: 4
    Last Post: 10-18-2011, 10:18 AM

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