简体   繁体   中英

Have to close my query in Microsoft Access 2013 each time I want to run a form

every time I want to run a form that searches through my database and returns results based on certain fields (login name, date, etc.) I must close out of the query if I want to change the search criteria. For example, if I search for login name "John" I get all those results, but if I then want to search for "Jerry" I have to close out of the query with the data first, then re-run the form.

Is there anyway around this?

--This applies to both Close and Opening method.

--Same applies to all the object(s) not just the query but also the Form etc.

To close a query you can use following code.

DoCmd.Close acQuery, "Queryname", acSaveNo

To explain it better,

DoCmd.Close is a method

it accepts following parameters.

  1. What to close (object type:acQuery, acForm etc)
  2. Name of the object (in this case Query name)
  3. Action to perform when closing (acSaveYes,acSaveNo,acSavePrompt).

Remember: Saving is actually saving the object(in this case Query) not the data. To Avoid Accidental modification of the query.I recommend closing the object without saving (unless required and know what you are doing)

acSaveYes: is to save the form with out notification. This is not saving the data, this is actually saving the object. So i recommend not doing this unless you want users to modify the query.

acSaveNo: This is close the query without saving.If you have users who would like to just view data and don't modify the query this is useful.

acSavePrompt: This is just prompting to either save the object or not.

Quick tip: While writing the query, if intellisense works then that means your cold is valid.

ref: https://msdn.microsoft.com/en-us/library/office/ff192860%28v=office.15%29.aspx

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM