Results 1 to 15 of 15
  1. #1
    Perfac's Avatar
    Perfac is offline Expert
    Windows 10 Access 2016
    Join Date
    May 2016
    Location
    Centurion Pretoria
    Posts
    618

    Requery or refresh Report

    Changing any info on a form, does not reflect immediately on a report. When exiting the form and returning the changes will then display on the report. I did add DoCmd.Requery under open on the Report. Adding refresh results in a different error. Is there a way to get the report to display the changed data instantly?
    Last edited by Perfac; 06-30-2022 at 09:03 AM.

  2. #2
    Gicu's Avatar
    Gicu is online now VIP
    Windows 10 Access 2010 32bit
    Join Date
    Jul 2015
    Location
    Kelowna, BC, Canada
    Posts
    4,111
    You need to save the form before opening the report so just add that before you open the report:
    Code:
    Me.Dirty=False 'saves the bound form's data
    Docmd.OpenReport....
    Cheers,
    Vlad Cucinschi
    MS Access Developer
    http://forestbyte.com/

  3. #3
    Perfac's Avatar
    Perfac is offline Expert
    Windows 10 Access 2016
    Join Date
    May 2016
    Location
    Centurion Pretoria
    Posts
    618
    Thank you. Did exactly what you suggested. Print button on Form, click event, VBA. Result is, report does not change even if I exit the Form and come back. Up to now the print Button Click event is connected by Macro like on the image, it works. All of my forms have a Save button. That never helped me to the required result. If the Macro can do it, please show me. If VBA will do it, please show me how the where condition must be. Eg Docmd.Openreport "r01Agents", acViewNormal "[AgtID]=[forms]![f01Agents]![AgtID]". I tried it like that but the filter doesn't work.
    Attachment 48176

  4. #4
    Join Date
    Jan 2017
    Location
    Swansea,South Wales,UK
    Posts
    4,906
    Invalid attachment.?
    If you have a Save button, is the form unbound?
    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
    Perfac's Avatar
    Perfac is offline Expert
    Windows 10 Access 2016
    Join Date
    May 2016
    Location
    Centurion Pretoria
    Posts
    618
    When I posted the first thread I saw the image afterwards and it was good. I will try again. My application has more than 200 forms. I don't think the save buttons have value. I do not know what you mean is the form unbound? This form is linked to a query. The Report is linked to the same query. The required result is when opening the report after changing any info on the form, the report must instantly display the changes made.
    Click image for larger version. 

Name:	Print.png 
Views:	19 
Size:	9.8 KB 
ID:	48178

  6. #6
    Gicu's Avatar
    Gicu is online now VIP
    Windows 10 Access 2010 32bit
    Join Date
    Jul 2015
    Location
    Kelowna, BC, Canada
    Posts
    4,111
    I don't use macros but as I suggested you need to save the form before you open the report if you want to see the changes. So if you want to stick to macros instead of VBA what you shot in your screen shot in post #5 needs to be the second "action" of the macro, not the first; the first should be something like SaveRecord or similar then your OpenReport. If you change to VBA you can use my suggestion in post # 2 for the syntax to change the form and follow that up with Docmd.OpenReport:
    https://docs.microsoft.com/en-us/off...cmd.openreport

    Cheers,
    Vlad
    Vlad Cucinschi
    MS Access Developer
    http://forestbyte.com/

  7. #7
    Perfac's Avatar
    Perfac is offline Expert
    Windows 10 Access 2016
    Join Date
    May 2016
    Location
    Centurion Pretoria
    Posts
    618
    Thank you. I tried everything you suggested, before you replied. No luck.

  8. #8
    Gicu's Avatar
    Gicu is online now VIP
    Windows 10 Access 2010 32bit
    Join Date
    Jul 2015
    Location
    Kelowna, BC, Canada
    Posts
    4,111
    Can you show us what you tried exactly?
    Cheers,

  9. #9
    Perfac's Avatar
    Perfac is offline Expert
    Windows 10 Access 2016
    Join Date
    May 2016
    Location
    Centurion Pretoria
    Posts
    618
    I added Saverecord as on the image to the Macro. The error message. "The command or action "Saverecord is not vailable now".
    Click image for larger version. 

Name:	Print02.png 
Views:	12 
Size:	14.0 KB 
ID:	48189

  10. #10
    Perfac's Avatar
    Perfac is offline Expert
    Windows 10 Access 2016
    Join Date
    May 2016
    Location
    Centurion Pretoria
    Posts
    618
    Private Sub btn19PrintFrm_Click()
    Me.Dirty = False
    DoCmd.OpenReport "r01Agents", acViewPreview
    End Sub

    Thank you.
    Just now I got the result I need with the above. Don't know what I did different previously. Maybe I added a comma.
    I still need to add the "where" condition.
    I just tested my thoughts how the "where condition' should be set up, but I fail. If you look at the way the Macro works? There are 9 agents in my Agents Table. I want to print the one that is open on the form only. Without the where condition it prints all 9.

  11. #11
    Join Date
    Jan 2017
    Location
    Swansea,South Wales,UK
    Posts
    4,906
    Use intellisense for the where argument location.
    Concatenate the agent id in the clause.
    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

  12. #12
    Perfac's Avatar
    Perfac is offline Expert
    Windows 10 Access 2016
    Join Date
    May 2016
    Location
    Centurion Pretoria
    Posts
    618
    While the form is open the Agent ID field "AgtID" returns the number of the record which should be printed In my case it is one page with all the information of one Agent. The code above in the macro does it successfully. But now I am changing to VBA on that button. Do you know exactly what I must add to get the where condition right?
    Eg. DoCmd.OpenReport "r01Agents", acViewPreview, =AgtID = forms!f01Agents!AgtID
    Should I add Me.AgtId, I tried already?

  13. #13
    Perfac's Avatar
    Perfac is offline Expert
    Windows 10 Access 2016
    Join Date
    May 2016
    Location
    Centurion Pretoria
    Posts
    618
    Private Sub btn19PrintFrm_Click()
    Me.Dirty = False
    DoCmd.OpenReport "r01Agents", acViewPreview, , "[AgtID]=forms!f01Agents!AgtID"
    End Sub

    Thank you. It work exactly correct like above.

  14. #14
    Join Date
    Jan 2017
    Location
    Swansea,South Wales,UK
    Posts
    4,906
    That should really be

    DoCmd.OpenReport "r01Agents", acViewPreview, , "[AgtID]=" & Me.AgtID
    if the code is in the form. Also what I meant by concatenation.
    However I have learnt something new today as well?
    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

  15. #15
    Gicu's Avatar
    Gicu is online now VIP
    Windows 10 Access 2010 32bit
    Join Date
    Jul 2015
    Location
    Kelowna, BC, Canada
    Posts
    4,111

    Glad to see you solved it... VBA good Macros b.. (a bit harder and trickier).

    Cheers,
    Vlad Cucinschi
    MS Access Developer
    http://forestbyte.com/

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

Similar Threads

  1. Form.Refresh not working (.requery does)
    By Bolduque in forum Forms
    Replies: 6
    Last Post: 01-10-2019, 03:04 PM
  2. VBA to Refresh/Requery a Form
    By justair07 in forum Programming
    Replies: 13
    Last Post: 01-23-2014, 11:19 AM
  3. Requery vs. Refresh
    By tylerg11 in forum Forms
    Replies: 3
    Last Post: 03-28-2012, 11:54 AM
  4. Refresh Requery Subform
    By eww in forum Programming
    Replies: 1
    Last Post: 04-05-2011, 09:19 AM
  5. Access novice help with refresh/requery
    By cvacgreg in forum Access
    Replies: 3
    Last Post: 02-04-2011, 08:51 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