I want my command button to run a query and then minimise the form in the same action

dal1503

Registered User.
Local time
Today, 04:57
Joined
Apr 14, 2016
Messages
34
I have a command button which runs a query based on the selection from a combo box. The query runs fine, but it appears in the background with the form still blocking the view of the query. I want the button to tell the database to run the query, then minimise the form. I've tried it using VBA and macros but for some reason the query runs but the form still doesn't minimise.

This is the code I have at the moment:

Code:
Private Sub cmdRunFamilyQuery_Click()
On Error GoTo cmdRunFamilyQuery_Click_Err

    DoCmd.OpenQuery cboFamilyQueries, acViewNormal, acReadOnly
    DoCmd.Minimize

cmdRunFamilyQuery_Click_Exit:
    Exit Sub

cmdRunFamilyQuery_Click_Err:
    MsgBox Error$
    Resume cmdRunFamilyQuery_Click_Exit

End Sub

If I create a separate button to minimise the form it works fine, but can't get it to work within the same button as the one that runs the query.

Any ideas if this is possible and how I can achieve it?

Thanks.
 
did you try reversing it:

DoCmd.Minimize
DoCmd.OpenQuery cboFamilyQueries, acViewNormal, acReadOnly
 
That worked. What an annoyingly simple solution, not that I should be complaining! Thanks
 

Users who are viewing this thread

Back
Top Bottom