Results 1 to 6 of 6
  1. #1
    ElDonJola is offline Novice
    Windows 10 Office 365
    Join Date
    Jun 2022
    Posts
    2

    Add calculated value from a subform to a form

    Hello everybody,

    I need some help. Long time ago I was quite good I VBA.. but most of it has gone.
    Following problem. I got a form having 5 fields of revenues generated by different payment channels (creditcard, card, online..). In the same form I have embedded 5 subforms, each of them calculating the revenues of the named payment methods.
    Now I'd like that access fills in the fields in the main form with the relevant values of the subforms.
    Could be by clicking a button on the main field, doing the job, so afterwards I can check if the values seem reasonable.

    I tried something but it end up with an error, telling me that it won't find the element:

    Private Sub TxtBar_DblClick(Cancel As Integer)
    Me![1 UF Cash].Form.SumBar = Me.Bar



    DoCmd.RunCommand acCmdSaveRecord
    End Sub

    Thanks a lot!!
    Attached Thumbnails Attached Thumbnails Access.png  

  2. #2
    Join Date
    Jan 2017
    Location
    Swansea,South Wales,UK
    Posts
    4,914
    Just refer to the subform controls that hold the totals.
    Please use # icon on toolbar when posting code snippets.
    Cross Posting: https://www.excelguru.ca/content.php?184
    Debugging Access: https://www.youtube.com/results?sear...bug+access+vba

  3. #3
    June7's Avatar
    June7 is online now VIP
    Windows 10 Access 2010 32bit
    Join Date
    May 2011
    Location
    The Great Land
    Posts
    52,901
    What do you mean by 'calculating the revenues' - what are these calcs? Are these subforms bound to tables? If code is behind main form, the expression is backwards.

    Me.Bar = Me.[1 UF Cash].Form.SumBar

    Strongly advise not to use spaces in naming convention. Also better not to start names with numbers.
    How to attach file: http://www.accessforums.net/showthread.php?t=70301 To provide db: copy, remove confidential data, run compact & repair, zip w/Windows Compression.

  4. #4
    ElDonJola is offline Novice
    Windows 10 Office 365
    Join Date
    Jun 2022
    Posts
    2
    Thank you for your post.
    The fields in the subforms are referring to queries. Each subform has one field, linked to one query in which dataset is filtered by payment method and generating the sum (Screenshot1). The field in the subform actually just shows the value of the sum (Screenshot 2).
    The SF and the form are linked with the ID called "RestaurantID"

    I'll change the names according naming convention
    Click image for larger version. 

Name:	Snapshot1.png 
Views:	21 
Size:	24.0 KB 
ID:	48126Click image for larger version. 

Name:	Screenshot2.png 
Views:	21 
Size:	32.1 KB 
ID:	48127

  5. #5
    June7's Avatar
    June7 is online now VIP
    Windows 10 Access 2010 32bit
    Join Date
    May 2011
    Location
    The Great Land
    Posts
    52,901
    Really should not be saving aggregate calculations to record, just calculate when needed.

    Also, using punctuation/special characters in names is just as bad as spaces.
    How to attach file: http://www.accessforums.net/showthread.php?t=70301 To provide db: copy, remove confidential data, run compact & repair, zip w/Windows Compression.

  6. #6
    kd2017 is offline Well, I tried at least.
    Windows 10 Access 2016
    Join Date
    Jul 2017
    Posts
    1,142
    +1 to welshgasman's suggestion, that's how I do it. No vba necessary.
    http://www.databasedev.co.uk/subform-total.html

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

Similar Threads

  1. Replies: 3
    Last Post: 06-29-2017, 03:02 PM
  2. Replies: 3
    Last Post: 06-24-2017, 06:39 PM
  3. Replies: 8
    Last Post: 10-10-2016, 06:07 AM
  4. Replies: 1
    Last Post: 07-10-2015, 06:38 PM
  5. Replies: 3
    Last Post: 04-04-2014, 07:14 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