SetFocus on query result

ethan.geerdes

Registered User.
Local time
Yesterday, 19:44
Joined
Jun 4, 2015
Messages
116
I have a query that is ran when I click a button. the result pops up but it comes up behind the form and i need the focus to shift and have it be up front.

Code:
Private Sub Command11_Click()
On Error GoTo Err_Command11_Click

    Dim stDocName As String

    stDocName = "system_qry"
    DoCmd.OpenQuery stDocName, acNormal, acEdit
   'stDocName.SetFocus
    
Exit_Command11_Click:
    Exit Sub

I am getting an error with this code, so I commented out the part which I thought would give me the correct result. Any information on this would be awesome. I don't know the syntax for referencing a query in VBA. I got a whole bunch of results for specifying a table though when I searched Google. I thought I would bring it up to the "Access gods". Any help would be greatly appreciated.
 
You probably have the calling form (where the button is), set as popup or modal which would force anything else to the back that isn't also set the same.

It's quite unusual to open a query view in edit mode as well, it's very easy for someone to over-type information in the query window if they aren't aware what form has the focus.
 
Code:
Private Sub Command11_Click()
On Error GoTo Err_Command11_Click

    Dim stDocName As String

    stDocName = "system_qry"
    DoCmd.OpenQuery stDocName, acNormal, acEdit
   'stDocName.SetFocus
    [COLOR=Blue]docmd.SelectObject acQuery,stDocName, false[/COLOR]
    
Exit_Command11_Click:
    Exit Sub
 

Users who are viewing this thread

Back
Top Bottom