Access VBA unable to refresh a form









up vote
0
down vote

favorite












I have a form (frmDropDownEdit) that has a filtered table as the data. A "New" button is created that opens another form (frmDropDownNew) and the user can enter new data. When complete the new form is closed and the user is back to the original form. The code for frmDropDownNew correctly add the info to the table, then the code refreshes the frmDropDownEdit form but it does not refresh. If I click the refresh button in the ribbon, it also does not refresh. But refresh all does work.



How can I have my code refresh the data in frmDropDownEdit. I also put code me.refresh on the OnGotFocus event but that does not even run.



Here is my source code



Private Sub Command5_Click()
'Add Button

Dim rst As DAO.Recordset
Set rst = CurrentDb.OpenRecordset("tblDropDown")
rst.AddNew

rst!DdCategory = Me.txtCategory.Value
rst!DdDescription = UCase(Me.txtDescription.Value)

rst.Update
rst.Close

DoCmd.Close
Forms!frmDropDownEdit.Refresh

End Sub









share|improve this question



















  • 1




    Change .Refresh to .Requery
    – Kostas K.
    Jun 2 '17 at 13:00










  • Yes, that worked. thank you
    – Charlie
    Jun 2 '17 at 13:28















up vote
0
down vote

favorite












I have a form (frmDropDownEdit) that has a filtered table as the data. A "New" button is created that opens another form (frmDropDownNew) and the user can enter new data. When complete the new form is closed and the user is back to the original form. The code for frmDropDownNew correctly add the info to the table, then the code refreshes the frmDropDownEdit form but it does not refresh. If I click the refresh button in the ribbon, it also does not refresh. But refresh all does work.



How can I have my code refresh the data in frmDropDownEdit. I also put code me.refresh on the OnGotFocus event but that does not even run.



Here is my source code



Private Sub Command5_Click()
'Add Button

Dim rst As DAO.Recordset
Set rst = CurrentDb.OpenRecordset("tblDropDown")
rst.AddNew

rst!DdCategory = Me.txtCategory.Value
rst!DdDescription = UCase(Me.txtDescription.Value)

rst.Update
rst.Close

DoCmd.Close
Forms!frmDropDownEdit.Refresh

End Sub









share|improve this question



















  • 1




    Change .Refresh to .Requery
    – Kostas K.
    Jun 2 '17 at 13:00










  • Yes, that worked. thank you
    – Charlie
    Jun 2 '17 at 13:28













up vote
0
down vote

favorite









up vote
0
down vote

favorite











I have a form (frmDropDownEdit) that has a filtered table as the data. A "New" button is created that opens another form (frmDropDownNew) and the user can enter new data. When complete the new form is closed and the user is back to the original form. The code for frmDropDownNew correctly add the info to the table, then the code refreshes the frmDropDownEdit form but it does not refresh. If I click the refresh button in the ribbon, it also does not refresh. But refresh all does work.



How can I have my code refresh the data in frmDropDownEdit. I also put code me.refresh on the OnGotFocus event but that does not even run.



Here is my source code



Private Sub Command5_Click()
'Add Button

Dim rst As DAO.Recordset
Set rst = CurrentDb.OpenRecordset("tblDropDown")
rst.AddNew

rst!DdCategory = Me.txtCategory.Value
rst!DdDescription = UCase(Me.txtDescription.Value)

rst.Update
rst.Close

DoCmd.Close
Forms!frmDropDownEdit.Refresh

End Sub









share|improve this question















I have a form (frmDropDownEdit) that has a filtered table as the data. A "New" button is created that opens another form (frmDropDownNew) and the user can enter new data. When complete the new form is closed and the user is back to the original form. The code for frmDropDownNew correctly add the info to the table, then the code refreshes the frmDropDownEdit form but it does not refresh. If I click the refresh button in the ribbon, it also does not refresh. But refresh all does work.



How can I have my code refresh the data in frmDropDownEdit. I also put code me.refresh on the OnGotFocus event but that does not even run.



Here is my source code



Private Sub Command5_Click()
'Add Button

Dim rst As DAO.Recordset
Set rst = CurrentDb.OpenRecordset("tblDropDown")
rst.AddNew

rst!DdCategory = Me.txtCategory.Value
rst!DdDescription = UCase(Me.txtDescription.Value)

rst.Update
rst.Close

DoCmd.Close
Forms!frmDropDownEdit.Refresh

End Sub






vba ms-access refresh






share|improve this question















share|improve this question













share|improve this question




share|improve this question








edited Jun 3 '17 at 4:23









PdC

1,072817




1,072817










asked Jun 2 '17 at 12:46









Charlie

62




62







  • 1




    Change .Refresh to .Requery
    – Kostas K.
    Jun 2 '17 at 13:00










  • Yes, that worked. thank you
    – Charlie
    Jun 2 '17 at 13:28













  • 1




    Change .Refresh to .Requery
    – Kostas K.
    Jun 2 '17 at 13:00










  • Yes, that worked. thank you
    – Charlie
    Jun 2 '17 at 13:28








1




1




Change .Refresh to .Requery
– Kostas K.
Jun 2 '17 at 13:00




Change .Refresh to .Requery
– Kostas K.
Jun 2 '17 at 13:00












Yes, that worked. thank you
– Charlie
Jun 2 '17 at 13:28





Yes, that worked. thank you
– Charlie
Jun 2 '17 at 13:28













1 Answer
1






active

oldest

votes

















up vote
0
down vote













On my MS Access 2010 ×64 single user PC, Forms![AnyForm] .Refresh never worked in VBA, independently where it is placed in any database's code. Form_Current() doesn't run either as it should after data are modified (verified by putting a Stop therein). Moreover, records with modified data are neither marked dirty nor refreshed before the vba code has finished. Procedures which should run without delay when data are modified don't run, even when placed into the modified fields' events.



Thus, one has to use a work-around. Many people recommend to use .Requery instead of .Refresh and then to return by vba code to the desired record, but this requires a field with a primary key.



My solution for tables without primary key is the following:



'…
' ESSENTIAL: this code must be run from ANOTHER module !
' (it runs without error in MyForm's own code [eg. in Form_Activate(),
' but then MyForm is NOT immediately refreshed as desired,)
' one still has to repeat these steps by hand afterwards…
DoCmd.GoToRecord acForm, "MyForm", acNext
DoCmd.GoToRecord acForm, "MyForm", acPrevious
' NB: Forms![MyForm].Refresh doesn't work
' at this place in "MyOtherModule" either.
'…


As mentioned in above code comments: this code must be run from another module ("MyOtherModule") - in my case, a form-independent procedure called upon closing a pop-up form opened from the first form, which interactively modifies data. These data should be updated/refreshed immediately when closing the pop-up form, reflecting all changes and their consequences (for example, automatic filling-in/deleting of other data and/or en/disabling controls or making them [in]visible, depending on the modified fields' values).






share|improve this answer




















    Your Answer






    StackExchange.ifUsing("editor", function ()
    StackExchange.using("externalEditor", function ()
    StackExchange.using("snippets", function ()
    StackExchange.snippets.init();
    );
    );
    , "code-snippets");

    StackExchange.ready(function()
    var channelOptions =
    tags: "".split(" "),
    id: "1"
    ;
    initTagRenderer("".split(" "), "".split(" "), channelOptions);

    StackExchange.using("externalEditor", function()
    // Have to fire editor after snippets, if snippets enabled
    if (StackExchange.settings.snippets.snippetsEnabled)
    StackExchange.using("snippets", function()
    createEditor();
    );

    else
    createEditor();

    );

    function createEditor()
    StackExchange.prepareEditor(
    heartbeatType: 'answer',
    convertImagesToLinks: true,
    noModals: true,
    showLowRepImageUploadWarning: true,
    reputationToPostImages: 10,
    bindNavPrevention: true,
    postfix: "",
    imageUploader:
    brandingHtml: "Powered by u003ca class="icon-imgur-white" href="https://imgur.com/"u003eu003c/au003e",
    contentPolicyHtml: "User contributions licensed under u003ca href="https://creativecommons.org/licenses/by-sa/3.0/"u003ecc by-sa 3.0 with attribution requiredu003c/au003e u003ca href="https://stackoverflow.com/legal/content-policy"u003e(content policy)u003c/au003e",
    allowUrls: true
    ,
    onDemand: true,
    discardSelector: ".discard-answer"
    ,immediatelyShowMarkdownHelp:true
    );



    );













    draft saved

    draft discarded


















    StackExchange.ready(
    function ()
    StackExchange.openid.initPostLogin('.new-post-login', 'https%3a%2f%2fstackoverflow.com%2fquestions%2f44329349%2faccess-vba-unable-to-refresh-a-form%23new-answer', 'question_page');

    );

    Post as a guest















    Required, but never shown

























    1 Answer
    1






    active

    oldest

    votes








    1 Answer
    1






    active

    oldest

    votes









    active

    oldest

    votes






    active

    oldest

    votes








    up vote
    0
    down vote













    On my MS Access 2010 ×64 single user PC, Forms![AnyForm] .Refresh never worked in VBA, independently where it is placed in any database's code. Form_Current() doesn't run either as it should after data are modified (verified by putting a Stop therein). Moreover, records with modified data are neither marked dirty nor refreshed before the vba code has finished. Procedures which should run without delay when data are modified don't run, even when placed into the modified fields' events.



    Thus, one has to use a work-around. Many people recommend to use .Requery instead of .Refresh and then to return by vba code to the desired record, but this requires a field with a primary key.



    My solution for tables without primary key is the following:



    '…
    ' ESSENTIAL: this code must be run from ANOTHER module !
    ' (it runs without error in MyForm's own code [eg. in Form_Activate(),
    ' but then MyForm is NOT immediately refreshed as desired,)
    ' one still has to repeat these steps by hand afterwards…
    DoCmd.GoToRecord acForm, "MyForm", acNext
    DoCmd.GoToRecord acForm, "MyForm", acPrevious
    ' NB: Forms![MyForm].Refresh doesn't work
    ' at this place in "MyOtherModule" either.
    '…


    As mentioned in above code comments: this code must be run from another module ("MyOtherModule") - in my case, a form-independent procedure called upon closing a pop-up form opened from the first form, which interactively modifies data. These data should be updated/refreshed immediately when closing the pop-up form, reflecting all changes and their consequences (for example, automatic filling-in/deleting of other data and/or en/disabling controls or making them [in]visible, depending on the modified fields' values).






    share|improve this answer
























      up vote
      0
      down vote













      On my MS Access 2010 ×64 single user PC, Forms![AnyForm] .Refresh never worked in VBA, independently where it is placed in any database's code. Form_Current() doesn't run either as it should after data are modified (verified by putting a Stop therein). Moreover, records with modified data are neither marked dirty nor refreshed before the vba code has finished. Procedures which should run without delay when data are modified don't run, even when placed into the modified fields' events.



      Thus, one has to use a work-around. Many people recommend to use .Requery instead of .Refresh and then to return by vba code to the desired record, but this requires a field with a primary key.



      My solution for tables without primary key is the following:



      '…
      ' ESSENTIAL: this code must be run from ANOTHER module !
      ' (it runs without error in MyForm's own code [eg. in Form_Activate(),
      ' but then MyForm is NOT immediately refreshed as desired,)
      ' one still has to repeat these steps by hand afterwards…
      DoCmd.GoToRecord acForm, "MyForm", acNext
      DoCmd.GoToRecord acForm, "MyForm", acPrevious
      ' NB: Forms![MyForm].Refresh doesn't work
      ' at this place in "MyOtherModule" either.
      '…


      As mentioned in above code comments: this code must be run from another module ("MyOtherModule") - in my case, a form-independent procedure called upon closing a pop-up form opened from the first form, which interactively modifies data. These data should be updated/refreshed immediately when closing the pop-up form, reflecting all changes and their consequences (for example, automatic filling-in/deleting of other data and/or en/disabling controls or making them [in]visible, depending on the modified fields' values).






      share|improve this answer






















        up vote
        0
        down vote










        up vote
        0
        down vote









        On my MS Access 2010 ×64 single user PC, Forms![AnyForm] .Refresh never worked in VBA, independently where it is placed in any database's code. Form_Current() doesn't run either as it should after data are modified (verified by putting a Stop therein). Moreover, records with modified data are neither marked dirty nor refreshed before the vba code has finished. Procedures which should run without delay when data are modified don't run, even when placed into the modified fields' events.



        Thus, one has to use a work-around. Many people recommend to use .Requery instead of .Refresh and then to return by vba code to the desired record, but this requires a field with a primary key.



        My solution for tables without primary key is the following:



        '…
        ' ESSENTIAL: this code must be run from ANOTHER module !
        ' (it runs without error in MyForm's own code [eg. in Form_Activate(),
        ' but then MyForm is NOT immediately refreshed as desired,)
        ' one still has to repeat these steps by hand afterwards…
        DoCmd.GoToRecord acForm, "MyForm", acNext
        DoCmd.GoToRecord acForm, "MyForm", acPrevious
        ' NB: Forms![MyForm].Refresh doesn't work
        ' at this place in "MyOtherModule" either.
        '…


        As mentioned in above code comments: this code must be run from another module ("MyOtherModule") - in my case, a form-independent procedure called upon closing a pop-up form opened from the first form, which interactively modifies data. These data should be updated/refreshed immediately when closing the pop-up form, reflecting all changes and their consequences (for example, automatic filling-in/deleting of other data and/or en/disabling controls or making them [in]visible, depending on the modified fields' values).






        share|improve this answer












        On my MS Access 2010 ×64 single user PC, Forms![AnyForm] .Refresh never worked in VBA, independently where it is placed in any database's code. Form_Current() doesn't run either as it should after data are modified (verified by putting a Stop therein). Moreover, records with modified data are neither marked dirty nor refreshed before the vba code has finished. Procedures which should run without delay when data are modified don't run, even when placed into the modified fields' events.



        Thus, one has to use a work-around. Many people recommend to use .Requery instead of .Refresh and then to return by vba code to the desired record, but this requires a field with a primary key.



        My solution for tables without primary key is the following:



        '…
        ' ESSENTIAL: this code must be run from ANOTHER module !
        ' (it runs without error in MyForm's own code [eg. in Form_Activate(),
        ' but then MyForm is NOT immediately refreshed as desired,)
        ' one still has to repeat these steps by hand afterwards…
        DoCmd.GoToRecord acForm, "MyForm", acNext
        DoCmd.GoToRecord acForm, "MyForm", acPrevious
        ' NB: Forms![MyForm].Refresh doesn't work
        ' at this place in "MyOtherModule" either.
        '…


        As mentioned in above code comments: this code must be run from another module ("MyOtherModule") - in my case, a form-independent procedure called upon closing a pop-up form opened from the first form, which interactively modifies data. These data should be updated/refreshed immediately when closing the pop-up form, reflecting all changes and their consequences (for example, automatic filling-in/deleting of other data and/or en/disabling controls or making them [in]visible, depending on the modified fields' values).







        share|improve this answer












        share|improve this answer



        share|improve this answer










        answered Nov 10 at 12:51









        Bughater

        86




        86



























            draft saved

            draft discarded
















































            Thanks for contributing an answer to Stack Overflow!


            • Please be sure to answer the question. Provide details and share your research!

            But avoid


            • Asking for help, clarification, or responding to other answers.

            • Making statements based on opinion; back them up with references or personal experience.

            To learn more, see our tips on writing great answers.





            Some of your past answers have not been well-received, and you're in danger of being blocked from answering.


            Please pay close attention to the following guidance:


            • Please be sure to answer the question. Provide details and share your research!

            But avoid


            • Asking for help, clarification, or responding to other answers.

            • Making statements based on opinion; back them up with references or personal experience.

            To learn more, see our tips on writing great answers.




            draft saved


            draft discarded














            StackExchange.ready(
            function ()
            StackExchange.openid.initPostLogin('.new-post-login', 'https%3a%2f%2fstackoverflow.com%2fquestions%2f44329349%2faccess-vba-unable-to-refresh-a-form%23new-answer', 'question_page');

            );

            Post as a guest















            Required, but never shown





















































            Required, but never shown














            Required, but never shown












            Required, but never shown







            Required, but never shown

































            Required, but never shown














            Required, but never shown












            Required, but never shown







            Required, but never shown







            Popular posts from this blog

            Use pre created SQLite database for Android project in kotlin

            Darth Vader #20

            Ondo