Results 1 to 13 of 13
  1. #1
    Bongobob21 is offline Novice
    Windows 7 32bit Access 2010 32bit
    Join Date
    Mar 2015
    Posts
    29

    Requery with Command button

    Hi everyone,



    I am totally new to this forum and also access in general and I have a small issue I think you can solve easily.
    I Created a form in which you can set different parameters Like Zipcode or company name. When all those values are entered you click the command button at it runs a query which will filter the table related to the Dropdown menus or text fields. My problem is that I have to click the refresh button every time I look at the query. is there a possibility with VBA to refresh the Query automatically, when you click the command Button?

    thank you and best regards,
    Andre

  2. #2
    amrut is offline Expert
    Windows 7 64bit Access 2010 32bit
    Join Date
    Jun 2012
    Location
    India
    Posts
    616
    You can requery the individual controls or entire form. Me.Requery or Me.ComboName.Requery

  3. #3
    Bongobob21 is offline Novice
    Windows 7 32bit Access 2010 32bit
    Join Date
    Mar 2015
    Posts
    29
    Thank you for your answer but I don"t really know where to put this command.
    Mein command button is called RunQuery and the textbox I use is called Zipcode. The Query which will be run when I click teh command button is called qryCustomer and I created the action that the command button should run the query with the query wizard if that changes anything. This is the code I tried in VBA but it doesn"t work.

    Private Sub RunQuery_Click()
    Me.Zipcode.Requery
    End Sub

    Sorry I am really at the beginning of using VBA and Access.

  4. #4
    lfpm062010 is offline Competent Performer
    Windows 7 64bit Access 2010 64bit
    Join Date
    Oct 2013
    Location
    US
    Posts
    415
    In Form Design, right click on the command button and select property (if not shown already).
    Find "On Got Focus" (or "On Enter"), and click on the dots, then enter you code (select "Code Builder" and type "me.zipcode.requery"). Should be something like this.

    Private Sub Command0_GotFocus()
    Me.Zipcode.Requery
    End Sub

  5. #5
    Bongobob21 is offline Novice
    Windows 7 32bit Access 2010 32bit
    Join Date
    Mar 2015
    Posts
    29
    Unfortunatly it doesn"t work but I also don't get a error message ... Isn't is possible to directly address the query and not the textfield?

  6. #6
    lfpm062010 is offline Competent Performer
    Windows 7 64bit Access 2010 64bit
    Join Date
    Oct 2013
    Location
    US
    Posts
    415
    Can you provide your db to look at?

    Remove any private, confidential, ... etc before posting.

  7. #7
    Bongobob21 is offline Novice
    Windows 7 32bit Access 2010 32bit
    Join Date
    Mar 2015
    Posts
    29
    Database4.zip

    I hope this will help you! thanks!

  8. #8
    lfpm062010 is offline Competent Performer
    Windows 7 64bit Access 2010 64bit
    Join Date
    Oct 2013
    Location
    US
    Posts
    415
    You are trying to requery a textbox and not a combo box.
    Instead of "On Focus" use "On Enter" instead.

    Hope this will solve your issue.

  9. #9
    Bongobob21 is offline Novice
    Windows 7 32bit Access 2010 32bit
    Join Date
    Mar 2015
    Posts
    29
    Code:
    Private Sub Form_Load()
    End Sub
    
    Private Sub Zipcode_Enter()
        Me.Zipcode.Requery
    End Sub
    
    Private Sub Command12_Click()
    End Sub
    Still no better result. I am not sure if it is clear what I want, I want to refresh the Query result automatically when you click the command button, so that you don't have to klick Refresh in the Topbar when you are in the query results. Sorry for my bad explanation, I hope I could make my issue more clear now.

  10. #10
    lfpm062010 is offline Competent Performer
    Windows 7 64bit Access 2010 64bit
    Join Date
    Oct 2013
    Location
    US
    Posts
    415
    You have a "TextBox" and a "Command Button" on the form. You really can't requery a "TexBox".

    When I run the form, enter the Zipcode information, and click on the "Run Query" button. It should me a data sheet with the Zipcode selected. It is working fine.

    You have to close the query result (Data Sheet) and re-enter your zipcode information and click on the "Run Query" button to see the new result.

  11. #11
    Bongobob21 is offline Novice
    Windows 7 32bit Access 2010 32bit
    Join Date
    Mar 2015
    Posts
    29
    Ok because that was my question, whether I can refresh the query without manually closing it? But referring to your statement this is not possible, Thanks!

  12. #12
    lfpm062010 is offline Competent Performer
    Windows 7 64bit Access 2010 64bit
    Join Date
    Oct 2013
    Location
    US
    Posts
    415
    You can put code in to close the query and re-run them. So, you don't have to manually close it.

    I think in the macro is "CloseWindows", "Query" for Object Type, and query name.

  13. #13
    Bongobob21 is offline Novice
    Windows 7 32bit Access 2010 32bit
    Join Date
    Mar 2015
    Posts
    29
    Great now it works, Thank you!

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

Similar Threads

  1. Replies: 1
    Last Post: 09-12-2014, 06:09 AM
  2. Requery split form data button
    By Evans2 in forum Forms
    Replies: 3
    Last Post: 09-08-2014, 08:59 PM
  3. Replies: 3
    Last Post: 08-04-2013, 07:11 AM
  4. command button
    By berni3883 in forum Forms
    Replies: 17
    Last Post: 04-22-2011, 12:04 AM
  5. Replies: 1
    Last Post: 07-27-2010, 02:27 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