Search code examples
sqlms-accessdatasheet

Microsoft Access - Search Query without opening Datasheet


Okay, so I have a dropdown box which is used as the input criteria for a query.

When I click the search button, it starts the query, opens a datasheet in a new page and lists company details based on the name that was selected in the combo box.

At the same time, I have a subform which displays these results on the main form itself. I want it to be able to display the results in the subform, without the query actually opening the datasheet page - How can I go about this?

Also, if I make a repeat search, the correct detais won't display until I press f5 (refresh), is there a way around this? - I tried making a macro, which works once; but after it works once the macro deletes itself.

.

P.S I'm not very good at SQL/VB code for access; I've done most things so far using the wizards and online tutorials, so if you could try and simplify things that would be a massive help! Thanks


Solution

  • After a bit of research; all I had to do was set an event procedure on my search button with the following code:

    Private Sub SearchButton_Click()
    
    Me.Subform_Name_Here.Form.Requery
    
    End Sub
    

    This automatically updates the details in my subform without it opening the query datasheet and having to refresh.