How to close auto-close Query result if not active

SachAccess

Active member
Local time
Today, 14:45
Joined
Nov 22, 2021
Messages
405
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
 
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.
 
Hi @theDBguy sir, thanks a lot for the help. Sure, I will keep this in mind.
Have a nice day ahead. :)
 
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

Back
Top Bottom