On close events for Queries in datasheet view

  • Thread starter Thread starter Guest
  • Start date Start date
G

Guest

Is there a way to make an event occur when you click the close button of a
query in dataview.

I have a query set up in VBA and it needs to be erased so when the user
clicks on the search button it can recreate the new query with the different
search criteria. right now I have it setup as:

Dim dbs As DAO.Database
Dim qdf As DAO.QueryDef

Set dbs = CurrentDb
Set qdf = dbs.CreateQueryDef("OBRQuery", strSQL)
DoCmd.OpenQuery "OBRQuery", , acReadOnly
dbs.QueryDefs.Delete ("OBRQuery")

and instead of deleting the query as soon as it's opened, it needs to wait
until after the user closes the form so they can sort the information in the
query. I tried putting the variable declerations and delete method before the
create method and it came up with an error.
 
hi,
Is there a way to make an event occur when you click the close button of a
query in dataview. No.

Dim dbs As DAO.Database
Dim qdf As DAO.QueryDef Dim WaitForClose As Boolean
Set dbs = CurrentDb
Set qdf = dbs.CreateQueryDef("OBRQuery", strSQL)
DoCmd.OpenQuery "OBRQuery", , acReadOnly

WaitForClose = True
Do While WaitForClose
Interaction.DoEvents
WaitForClose = (acSysCmdGetObjectState, acQuery, qdf.Name) = 1) _
And _
(CodeData.AllQueries.Item(qdf.Name).CurrentView = 2)
Loop
dbs.QueryDefs.Delete ("OBRQuery")
May work.

Better solution is to test wether the query is opened _before_
recreating it.


mfG
--> stefan <--
 
hi,

Stefan said:
Do While WaitForClose
Interaction.DoEvents
WaitForClose = (acSysCmdGetObjectState, acQuery, qdf.Name) = 1) _

SysCmd is missing:
WaitForClose = (SysCmd(acSysCmdGetObjectState, acQuery, qdf.Name) = 1) _
And _
(CodeData.AllQueries.Item(qdf.Name).CurrentView = 2)
Loop

mfG
--> stefan <--
 
hi,
and instead of deleting the query as soon as it's opened, it needs to wait
until after the user closes the form so they can sort the information in the
query. I tried putting the variable declerations and delete method before the
create method and it came up with an error.
In this case - forget to mention this - you have to call
dbs.QueryDefs.Requery.
Set dbs = CurrentDb dbs.QueryDefs.Requery
dbs.QueryDefs.Delete ("OBRQuery")
Set qdf = dbs.CreateQueryDef("OBRQuery", strSQL)
DoCmd.OpenQuery "OBRQuery", , acReadOnly


mfG
--> stefan <--
 
Back
Top