How to close auto-close Query result if not active (1 Viewer)

SachAccess

Active member
Local time
Today, 13:46
Joined
Nov 22, 2021
Messages
389
Hi,

I have a Form in my DB.
I have provided a Button in my DB.
Button is linked to below code.
Once clicked it takes user to query result.
At present when user clicks on button ‘Code and Name ‘ from ‘Emp Code and Name’ form.
Both query ‘Q_Select_Only_Two_Column’ and form ‘Emp Code and Name’ are visible, which is fine.

However when user returns to form even then also both are visible.
My question is, once user is back to Form how do I auto-close the query result.
Thanks.
Code:
Option Compare Database
'Form Get Employee Details
Private Sub Command5_Click()
DoCmd.OpenQuery "Q_Select_Only_Two_Column"
End Sub
 

theDBguy

I’m here to help
Staff member
Local time
Today, 01:16
Joined
Oct 29, 2018
Messages
21,447
Hi. You could try using the DoCmd.Close method in the Activate event of the Form. However, you shouldn't give users direct access to query result. You could create a form to display the result of the query and then use DoCmd.Close in its LostFocus event.
 

SachAccess

Active member
Local time
Today, 13:46
Joined
Nov 22, 2021
Messages
389
Hi @theDBguy sir, thanks a lot for the help. Sure, I will keep this in mind.
Have a nice day ahead. :)
 

Pat Hartman

Super Moderator
Staff member
Local time
Today, 04:16
Joined
Feb 19, 2002
Messages
43,196
I'll be a little more direct. Do NOT give users direct access to tables or queries. You have no control over what they might do and accidents happen. Always use forms or reports to display/edit data. In a form, you can validate the data entry and ensure that values are rational and rows are not deleted unless you allow them to be.
 

Users who are viewing this thread

Top Bottom