Page 1 of 2 12 LastLast
Results 1 to 15 of 23
  1. #1
    jlindquist23 is offline Advanced Beginner
    Windows 7 64bit Access 2016
    Join Date
    Jan 2019
    Posts
    43

    Real Time Calculations

    I have a formula in a subform (also have the same formula in the main form) that counts how many boxes are checked in the Rerun column.

    It will only calculate the total if I toggle the record forward and back on the main form.

    How do I get that to calculate in real time?



    I'd like to send an email from outlook when the count is greater than zero.
    I have a field called RerunTorF that changes to a 1 when the count goes over zero.



    The email does not trigger (I have checked the box to turn on Microsoft outlook 16.0 Object Library) . I've shown the code below:

    Private Sub RerunTorF_Change()

    Dim Msg As String

    Msg = "All" & ",<P>" & _
    "Heat treat line " & HeatTreatLine & " has parts that have been rerun. Please inspect for quality."

    Dim O As Outlook.Application
    Dim M As Outlook.MailItem

    Set O = New Outlook.Application
    Set M = O.CreateItem(olMailItem)

    With M
    .BodyFormat = olFormatHTML
    .HTMLBody = "Msg"
    .To "jlindquist@whirltronics.com"
    .Subject = "HEAT TREAT LINE RERUNS " & Now()
    .Send 'If you want it to send immediately
    End With

    Set M = Nothing
    Set O = Nothing


    End Sub

  2. #2
    kd2017 is offline Well, I tried at least.
    Windows 10 Access 2016
    Join Date
    Jul 2017
    Posts
    1,142
    You're missing an equal sign = in the .To line
    Code:
    .To = "jlindquist@whirltronics.com"
    Your .HTMLBody should be set to Msg, not "Msg"
    Code:
    .HTMLBody = Msg
    HeatTreatLine isn't declared (in this code snippit anyway)

    As far as the rerun column calcs, where is the formula? what is the formula? What's triggering the formula calculation?

  3. #3
    jlindquist23 is offline Advanced Beginner
    Windows 7 64bit Access 2016
    Join Date
    Jan 2019
    Posts
    43
    Thank you for catching the code issues.

    I don't quite understand how to fix the HeatTreatLine one.

    The main form is called HTRecord.
    The calculation is inside a subform called LoadData_Subform

    The HeatTreatLine variable is outside the LoadData_Subform in the HTRecord. Help on how to declare that variable would be appreciated!

  4. #4
    Join Date
    Jan 2017
    Location
    Swansea,South Wales,UK
    Posts
    4,943
    Pass HeatTreatLine into the sub as a parameter, or make it a TempVar ?
    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

  5. #5
    jlindquist23 is offline Advanced Beginner
    Windows 7 64bit Access 2016
    Join Date
    Jan 2019
    Posts
    43
    Thank you for catching the code issues.

    I don't quite understand how to fix the HeatTreatLine one.

    The main form is called HTRecord.
    The calculation is inside a subform called LoadData_Subform

    The HeatTreatLine variable is outside the LoadData_Subform in the HTRecord. Help on how to declare that variable would be appreciated!
    The main form HTRecord that has the HeatTreatLine is pulling from a query called Joined_Qry

  6. #6
    jlindquist23 is offline Advanced Beginner
    Windows 7 64bit Access 2016
    Join Date
    Jan 2019
    Posts
    43
    I have the calculation in the form footer of the LoadData_Subform and seems to be updating now when I move to a new line.


    new code is:

    Private Sub Text74_AfterUpdate()
    Dim Msg As String

    Msg = "All" & ",<P>" & _
    "Heat treat line " & Forms![HTRecord]![HeatTreatLine] & " has parts that have been rerun. Please inspect for quality."

    'Remember to add REFERENCE to Microsoft Outlook Library'

    Dim O As Outlook.Application
    Dim M As Outlook.MailItem

    Set O = New Outlook.Application
    Set M = O.CreateItem(olMailItem)

    With M
    .BodyFormat = olFormatHTML
    .HTMLBody = Msg
    .Display = "jlindquist@whirltronics.com"
    '.CC = "anyone@Whirltronics.com
    '.BCC = "anyone@whirltronics.com
    .Subject = "HEAT TREAT LINE RERUNS " & Now()
    'Display -- if you want it to come up on the screen before it gets sent
    .Send 'If you want it to send immediately
    End With

    Set M = Nothing
    Set O = Nothing
    End Sub

  7. #7
    kd2017 is offline Well, I tried at least.
    Windows 10 Access 2016
    Join Date
    Jul 2017
    Posts
    1,142
    Sounds like good news!

    Are your issues resolved?

  8. #8
    pbaldy's Avatar
    pbaldy is offline Who is John Galt?
    Windows XP Access 2007
    Join Date
    Feb 2010
    Location
    Nevada, USA
    Posts
    22,521
    FYI I think your original issue was expecting the change event to fire when the control's value was being changed by an underlying calculation/requery. That event will only fire when the user changes the value in the textbox, not when it changes for other reasons. It looks like you found a good solution, the after update event of a control the user is changing.
    Paul (wino moderator)
    MS Access MVP 2007-2019
    www.BaldyWeb.com

  9. #9
    jlindquist23 is offline Advanced Beginner
    Windows 7 64bit Access 2016
    Join Date
    Jan 2019
    Posts
    43
    I still can't get the email part to work.

  10. #10
    kd2017 is offline Well, I tried at least.
    Windows 10 Access 2016
    Join Date
    Jul 2017
    Posts
    1,142
    Quote Originally Posted by jlindquist23 View Post
    I still can't get the email part to work.
    For future reference you will usually get the best help if you can also tell us if your getting any error messages or anything like that. "it doesn't work" doesn't help us much on our end since we can't see what's going on at your end.

    To me the issue appears to be that this
    Code:
    .Display = "jlindquist@whirltronics.com"
    is supposed to be this:
    Code:
    .To = "jlindquist@whirltronics.com"

  11. #11
    jlindquist23 is offline Advanced Beginner
    Windows 7 64bit Access 2016
    Join Date
    Jan 2019
    Posts
    43
    Oh yes...my apologies.
    I've tried both of those codes you show above
    I get no error messages ... nothing happens

  12. #12
    Join Date
    Jan 2017
    Location
    Swansea,South Wales,UK
    Posts
    4,943
    Check the variables abd objects in the Locals window.
    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

  13. #13
    Micron is offline Virtually Inert Person
    Windows 10 Access 2016
    Join Date
    Jun 2014
    Location
    Ontario, Canada
    Posts
    12,803
    I get no error messages ... nothing happens
    Respond to post and address what is in post 8? Your code works (does create an email with body text) as long as a value is substituted for the forms reference. That won't matter at your end.
    Last edited by Micron; 06-20-2023 at 10:59 AM. Reason: clarification
    The more we hear silence, the more we begin to think about our value in this universe.
    Paraphrase of Professor Brian Cox.

  14. #14
    jlindquist23 is offline Advanced Beginner
    Windows 7 64bit Access 2016
    Join Date
    Jan 2019
    Posts
    43
    Can you say more about checking the variables and objects in the locals window?
    Do I need to define the Forms![HTRecord]![HeatTreatLine] as a variable? See first part of code below.

    I tried this and still nothing happens. No errors or emails sent or created.

    Private Sub RerunCountMain_AfterUpdate()
    Dim Msg As String
    Dim HTLine As String

    HTLine = Forms![HTRecord]![HeatTreatLine]

    Msg = "All" & ",<P>" & _
    "Heat treat line " '& HTLine & " has parts that have been rerun. Please inspect for quality."

  15. #15
    pbaldy's Avatar
    pbaldy is offline Who is John Galt?
    Windows XP Access 2007
    Join Date
    Feb 2010
    Location
    Nevada, USA
    Posts
    22,521
    Are you sure the code is even running? Throw in a message box or debug.print on the Msg variable and see if it gets triggered.
    Paul (wino moderator)
    MS Access MVP 2007-2019
    www.BaldyWeb.com

Page 1 of 2 12 LastLast
Please reply to this thread with any new information or opinions.

Similar Threads

  1. Displaying new subforms in real time.
    By sgp667 in forum Forms
    Replies: 4
    Last Post: 10-22-2012, 04:01 PM
  2. Real Time Incremental Back Up
    By GrnMtn7 in forum Access
    Replies: 1
    Last Post: 10-15-2011, 05:29 PM
  3. real time clock
    By krai in forum Access
    Replies: 1
    Last Post: 05-13-2010, 05:11 AM
  4. Real time database question
    By joet5402 in forum Forms
    Replies: 7
    Last Post: 04-01-2009, 09:00 PM
  5. Update a combo box in real time
    By protean_being in forum Forms
    Replies: 0
    Last Post: 05-17-2008, 07:39 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