Results 1 to 7 of 7
  1. #1
    Pete-RM is offline Novice
    Windows 8 Access 2013
    Join Date
    Jun 2015
    Posts
    8

    Post Update Form / Query data in real time

    I have created a database to develop meal plans and apply them to different days.

    I have a form called 'frmMainDay' which allows me to apply different meals to specific days, along with 4 total fields for each meal (this is done by navigating the subform 'frmSubDay') (there are 4 totals because I am going to use this as a template for various databases). Note that the 4th total simply sums the other 3 totals together.

    My main form contains fields that sum the total fields in the subform. This may sound confusing so I will provide an example (assuming that you have my db. file open).

    For example, the 'DayTotal' field on the main form sums the 'Totaltest' field on the subform. So, for example, on Day 1 the 'DayTotal' field would equal 102+550 because there are 2 meals on this day.

    The total fields on the main form (DayTotal, etc) are generated through the query 'qryDayTotal'.

    Here is my issue:

    When I enter a new meal into my form (i.e. a new row in the subform) the fields 'DayTotal', 'DayTotal2', etc on the main form do not update with the new totals. They only update if I close the form and then re-open it.

    Please help me to figure out a way to make the fields on the main form update in real time without having to close the form or go to the next record.



    Also please note that I am very new to Access and have basically no knowedge of Visual Basic or writing code.

    All help is appreciated.

    the db. file is attached
    Attached Files Attached Files

  2. #2
    rpeare is offline VIP
    Windows XP Access 2003
    Join Date
    Jul 2011
    Posts
    5,442
    This not a super great design for you but you can get what you want by clicking on the subform and adding this to the AFTER UPDATE event of the subform:

    forms!frmmainday!list27.requery

    This should force a refresh after a new item is added to your table storing the items in the subform.

  3. #3
    Pete-RM is offline Novice
    Windows 8 Access 2013
    Join Date
    Jun 2015
    Posts
    8
    Quote Originally Posted by rpeare View Post
    This not a super great design for you but you can get what you want by clicking on the subform and adding this to the AFTER UPDATE event of the subform:

    forms!frmmainday!list27.requery

    This should force a refresh after a new item is added to your table storing the items in the subform.

    Thanks that helped a lot!

    Just putting the formula into the AFTER UPDATE event didn't work but it worked when I also added it to GOT FOCUS or LOST FOCUS. (Note: I also had to add an equals sign to the front of the formula)

    I have a small new problem now, the first time I select a combo box it closes automatically.

    This does not happen if the field is already selected (i.e. if I tab to the field first).

    I assume it closes because the form is refreshing when the field 'Gets Focus'.

    Is there any way around this?

    Also note that I did not have to apply the formula to the whole subform, it worked when I just applied it to the first 'MealID' field in the subform.

  4. #4
    rpeare is offline VIP
    Windows XP Access 2003
    Join Date
    Jul 2011
    Posts
    5,442
    the GOT FOCUS/LOST FOCUS events happen when the form becomes or loses it's 'main' item status. For instance if you have two forms open and you tab between them, the GOT FOCUS for the form will trigger every time you tab to the form. If you are using code you do not need an equals sign, that's why I didn't put one in. To play around with WHEN your code is triggering you can put notes in your code like

    msgbox "GOT FOCUS IS TRIGGERING HERE"
    msgbox "LOST FOCUS IS TRIGGERING HERE"

    and so on, so you can pick out the appropriate 'break' point to issue your refresh command.

    This is, of course assuming you're using vb code and not a macro.

  5. #5
    Pete-RM is offline Novice
    Windows 8 Access 2013
    Join Date
    Jun 2015
    Posts
    8
    Is there a way to requery as soon as I select an item from the 'MealID' combobox and prevent getting the issue I described above?

  6. #6
    rpeare is offline VIP
    Windows XP Access 2003
    Join Date
    Jul 2011
    Posts
    5,442
    You can use the ON CHANGE event of MealID, however I would most likely use the ON EXIT event, ON CHANGE doesn't always function the way I want and ON EXIT or AFTER UPDATE might give you a better result.

  7. #7
    Pete-RM is offline Novice
    Windows 8 Access 2013
    Join Date
    Jun 2015
    Posts
    8
    Quote Originally Posted by rpeare View Post
    You can use the ON CHANGE event of MealID, however I would most likely use the ON EXIT event, ON CHANGE doesn't always function the way I want and ON EXIT or AFTER UPDATE might give you a better result.
    I tried this but got the same issue that I got with the got focus command. I guess it isnt that big a problem anyway, thankyou for getting me this far

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

Similar Threads

  1. Update the Customer No in real time
    By gstylianou in forum Access
    Replies: 6
    Last Post: 06-08-2014, 09:38 AM
  2. real-time data integration of csv file into access
    By nlsoe in forum Import/Export Data
    Replies: 4
    Last Post: 10-17-2012, 06:57 AM
  3. Blueprint for SQL data to excel in real time.
    By greggue in forum Programming
    Replies: 1
    Last Post: 12-21-2010, 12:39 PM
  4. Data management and real time data
    By fsmikwen in forum Import/Export Data
    Replies: 1
    Last Post: 03-11-2010, 10:44 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