none
requery problem RRS feed

  • Question

  • By means of a pop-up form I want to add a new contact and see the data of this new contact in a listbox on my main form. After filling in the new contact I close the form to see the result. However I receive the error number 2118, "the action cannot be executed before the present field is stored".

    I use the following code in the pop-up form:

    sub form_unload

      forms!mainform.listbox.requery

    exit sub

    PS: The data which I have entered in the pop-up form are present: After I close and re-open  the main form I can see the new data in the listbox.

    Jantje

    Monday, June 27, 2016 8:05 AM

Answers

  • Does your main form include the contacts table in it's recordsource query?

    If so, try saving the main form data before opening the popup form:

    Docmd.Runcommand acCmdSaveRecord
    Docmd.OpenForm "MyPopupForm"
     

    Additionally, try using the popup form's Close Event (which is the final event as the popup form closes) for the requery.  See the following for form/control order of events:

    Order of Events for Access Form and Controls


    Miriam Bizup Access MVP

    Monday, June 27, 2016 8:47 AM

All replies

  • Does your main form include the contacts table in it's recordsource query?

    If so, try saving the main form data before opening the popup form:

    Docmd.Runcommand acCmdSaveRecord
    Docmd.OpenForm "MyPopupForm"
     

    Additionally, try using the popup form's Close Event (which is the final event as the popup form closes) for the requery.  See the following for form/control order of events:

    Order of Events for Access Form and Controls


    Miriam Bizup Access MVP

    Monday, June 27, 2016 8:47 AM
  • You might like to take a look at NotInList.zip in my public databases folder at:

    https://onedrive.live.com/?cid=44CC60D7FEA42912&id=44CC60D7FEA42912!169

    Note that if you are using an earlier version of Access you might find that the colour of some form objects such as buttons shows incorrectly and you will need to amend the form design accordingly.  

    If you have difficulty opening the link copy its text (NB, not the link location) and paste it into your browser's address bar.

    In this little demo file  the code behind the 'Add New Contact' button on the opening form illustrates what you are trying to do.  The relevant control in my demo is a combo box, not a list box, but that is irrelevant.

    Ken Sheridan, Stafford, England


    • Edited by Ken Sheridan Monday, June 27, 2016 11:15 AM Typo corrected.
    Monday, June 27, 2016 11:14 AM