Page 1 of 2 12 LastLast
Results 1 to 15 of 28
  1. #1
    accessnewb is offline Competent Performer
    Windows 7 32bit Access 2007
    Join Date
    Jul 2011
    Location
    New York, NY
    Posts
    116

    Closing a form automatically

    Hi all,


    I just started using access last week and it's been OK so far. But today, I discovered this very annoying issue:

    I have created a form and a search button in that. When I click on the button, a query is executed, and I am taken to a new form with the search results. Now, the problem is, I have to explicitly close the search result everytime in order to do a new search. If I don't do that then I am still shown the old results. That kinda sucks. Is there any way to recity this? Some in-built feature in access??
    Last edited by accessnewb; 07-18-2011 at 01:01 PM. Reason: Make it more clear

  2. #2
    boblarson is offline --------
    Windows 7 64bit Access 2010 32bit
    Join Date
    Jun 2011
    Posts
    1,272
    1. Why are you creating a new table for the search instead of just using the query results in a form?

    2. Yes, you have to understand that a table that you are viewing is just another query. It isn't really the table. It is a system VIEW of the data. You can never really look at the actual table. So, like any query you have to requery it to get any changes that have occurred since you opened it last.

  3. #3
    June7's Avatar
    June7 is online now VIP
    Windows XP Access 2010 32bit
    Join Date
    May 2011
    Location
    The Great Land
    Posts
    52,891
    If you change the search criteria then the form must be closed then reopened or requeried. Is the button VBA or macro code? Post code for analysis.
    How to attach file: http://www.accessforums.net/showthread.php?t=70301 To provide db: copy, remove confidential data, run compact & repair, zip w/Windows Compression.

  4. #4
    accessnewb is offline Competent Performer
    Windows 7 32bit Access 2007
    Join Date
    Jul 2011
    Location
    New York, NY
    Posts
    116
    @borlarson: I am really new to access, and I don't know how to code in vb as of yet. I wrote a query and the results of the query is automatically generated in a new table. I also created another button to generate the result in a form. But I need to close the table/form in order to view the new result.

    @June7: The code is not creating tables! The results of the query are automatically generated in a table. A part of the query is below:

    SELECT *
    FROM tableName AS t
    WHERE (t.FieldName1 Like IIf(IsNull(FORMS!FormName!Text34),"*",(FORMS!FormN ame!Text34)) Or (IIf(IsNull(FORMS!FormName!Text34),t.FieldName1 is null))) And (t.FieldName2 Like IIf(IsNull(FORMS!FormName!Text35),"*",(FORMS!FormN ame!Text35)) Or (IIf(IsNull(FORMS!FormName!Text35),t.FieldName2 is null))) ;

  5. #5
    boblarson is offline --------
    Windows 7 64bit Access 2010 32bit
    Join Date
    Jun 2011
    Posts
    1,272
    Quote Originally Posted by accessnewb View Post
    @June7: The code is not creating tables! The results of the query are automatically generated in a table. A part of the query is below:

    SELECT *
    FROM tableName AS t
    WHERE (t.FieldName1 Like IIf(IsNull(FORMS!FormName!Text34),"*",(FORMS!FormN ame!Text34)) Or (IIf(IsNull(FORMS!FormName!Text34),t.FieldName1 is null))) And (t.FieldName2 Like IIf(IsNull(FORMS!FormName!Text35),"*",(FORMS!FormN ame!Text35)) Or (IIf(IsNull(FORMS!FormName!Text35),t.FieldName2 is null))) ;
    a PART of the query is below? What is the rest of it?

  6. #6
    accessnewb is offline Competent Performer
    Windows 7 32bit Access 2007
    Join Date
    Jul 2011
    Location
    New York, NY
    Posts
    116
    @boblarson: sorry, I should have explained better. There are like 20 fields in the table and the query is the same for each field. I thought it would be redundant to post the entire query, so jus copy-pasted the query for 2 of the fields.

  7. #7
    boblarson is offline --------
    Windows 7 64bit Access 2010 32bit
    Join Date
    Jun 2011
    Posts
    1,272
    So in other words you are just opening a query. You said it was opening in a table but what you really meant was that it was just opening the query (which looks like what a table looks like when you open one).

    So you have to close that query to run it again. You should be able to hit the red exclamation mark from the query to requery it once you've changed the criteria on the form. But the simplest is to just build a form based on the query (and you can display it in datasheet view which will then look like it is the table/query) and then in your code or macro to open the results form you can issue a requery to update the recordset of the form so it doesn't have to be closed and reopened.

  8. #8
    accessnewb is offline Competent Performer
    Windows 7 32bit Access 2007
    Join Date
    Jul 2011
    Location
    New York, NY
    Posts
    116
    Quote Originally Posted by boblarson View Post
    and then in your code or macro to open the results form you can issue a requery to update the recordset of the form so it doesn't have to be closed and reopened.
    Can you explain how I can do this? Like I said, I am super new to access and I have no clue how to do that. Maybe you can post a link to some code?

  9. #9
    boblarson is offline --------
    Windows 7 64bit Access 2010 32bit
    Join Date
    Jun 2011
    Posts
    1,272
    First off, go to your query in the navigation pane and click on the query to select it but don't open it. Then go to the CREATE TAB and under the forms area click MORE FORMS which then should give you a DATASHEET option. Select that and your form should be built to display your results from your query. Name it something like frmResults. Then with your other form (the one which has the criteria and, I assume, the button to open the query currently) go into design view and then select the button and go to the event properties. Does it say [Embedded Macro] there?

  10. #10
    accessnewb is offline Competent Performer
    Windows 7 32bit Access 2007
    Join Date
    Jul 2011
    Location
    New York, NY
    Posts
    116
    Yep, it does say [embedded macro] there.

  11. #11
    June7's Avatar
    June7 is online now VIP
    Windows XP Access 2010 32bit
    Join Date
    May 2011
    Location
    The Great Land
    Posts
    52,891
    Don't know about Bob, but I use only VBA, not macros, for coding. Either way, code would have to be modified to check if the form is open and if it is, requery, if not open then open. I have no idea if macro can handle this. In VBA I use IsLoaded, something like:

    If CurrentProject.AllForms("formname").IsLoaded Then
    formname.Requery
    Else
    DoCmd.OpenForm "formname"
    End If
    How to attach file: http://www.accessforums.net/showthread.php?t=70301 To provide db: copy, remove confidential data, run compact & repair, zip w/Windows Compression.

  12. #12
    accessnewb is offline Competent Performer
    Windows 7 32bit Access 2007
    Join Date
    Jul 2011
    Location
    New York, NY
    Posts
    116
    @June7: For what event do I use that code? For the OnLostFocus event?

  13. #13
    June7's Avatar
    June7 is online now VIP
    Windows XP Access 2010 32bit
    Join Date
    May 2011
    Location
    The Great Land
    Posts
    52,891
    Maybe in the 'Search' button click event.
    How to attach file: http://www.accessforums.net/showthread.php?t=70301 To provide db: copy, remove confidential data, run compact & repair, zip w/Windows Compression.

  14. #14
    accessnewb is offline Competent Performer
    Windows 7 32bit Access 2007
    Join Date
    Jul 2011
    Location
    New York, NY
    Posts
    116
    @June7: The code doesn't work. I still need to explicitly close the results tab to requery

  15. #15
    June7's Avatar
    June7 is online now VIP
    Windows XP Access 2010 32bit
    Join Date
    May 2011
    Location
    The Great Land
    Posts
    52,891
    Did you do as VBA procedure? If so, the Event property needs to be [Event Procedure].

    Post your complete procedure and/or project for analysis.
    How to attach file: http://www.accessforums.net/showthread.php?t=70301 To provide db: copy, remove confidential data, run compact & repair, zip w/Windows Compression.

Page 1 of 2 12 LastLast
Please reply to this thread with any new information or opinions.

Similar Threads

  1. Closing a form through VBA
    By ghostmachine in forum Forms
    Replies: 4
    Last Post: 12-13-2010, 01:57 PM
  2. Closing and saving a form
    By Lxmanager in forum Forms
    Replies: 14
    Last Post: 11-21-2010, 02:04 AM
  3. Prevent a form from closing
    By ksmithson in forum Forms
    Replies: 0
    Last Post: 07-15-2010, 12:49 PM
  4. Replies: 1
    Last Post: 06-25-2010, 09:56 AM
  5. Closing a Form Problem
    By MuskokaMad in forum Forms
    Replies: 2
    Last Post: 03-18-2010, 05:58 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