One after the other.

S

Shotodru

Dear Friends,
I have stumbled across a situation - the solution for which may be
ridiculously simple. However, the solution itself avoids me thus far.

Please could you suggest ways and means as to how I can prevent a report
immediately showing up after a particular query results have been displayed.

In other words, I have created code for a command button which displays the
results of the query first and then a report based on it next. However, even
before the user has closed the query results window, the report pops up.

Can anyone help me solve this issue. I want the user to be able to view the
results of the query first, close the query results window and then be able
to view the report.

Best regards,
Satadru.
 
G

George Nicholson

I want the user to be able to view the
results of the query first, close the query results window and then be
able
to view the report.

Copy the 2 procedures below into a general module and then insert the
"WaitUntilClosed" line between your existing OpenQuery/OpenReport.
DoCmd.OpenQuery "MyQuery", acViewNormal, acReadOnly
WaitUntilClosed "MyQuery", acQuery
DoCmd.OpenReport "MyReport", strReport, acViewPreview

** The following 2 routines should be placed in a general code module.
** If you don't already have one: VB Editor>Insert>Module

Public Sub WaitUntilClosed(strObjName As String, Optional lngObjType As
acObjecttype = acForm)
' Suspends code execution while object is open. Default object is a
Form.
On Error Resume Next
Do While IsLoaded(strObjName, lngObjType)
DoEvents
Loop
End Sub

Public Function IsLoaded(strObjName As String, Optional lngObjType As
acObjecttype = acForm) As Boolean
' Returns True if strName is Open (non-zero), False(0) otherwise.
' Should return 0, not an error, if the object doesn't exist
' Default Object is Form
On Error Resume Next
IsLoaded = (SysCmd(acSysCmdGetObjectState, lngObjType, strObjName) <> 0)
End Function

HTH,
 
J

John Vinson

Dear Friends,
I have stumbled across a situation - the solution for which may be
ridiculously simple. However, the solution itself avoids me thus far.

Please could you suggest ways and means as to how I can prevent a report
immediately showing up after a particular query results have been displayed.

In other words, I have created code for a command button which displays the
results of the query first and then a report based on it next. However, even
before the user has closed the query results window, the report pops up.

Can anyone help me solve this issue. I want the user to be able to view the
results of the query first, close the query results window and then be able
to view the report.

Rather than displaying the query Datasheet, base a Form on the query.
Open it in Dialog mode:

DoCmd.OpenReport "reportname", WindowMode:=acDialog

followeed by the code to open the Report.

When a form is opened in Dialog mode, the calling code pauses until
the form is closed or made invisible.

John W. Vinson[MVP]
 
S

Shotodru

George/John,
You are real life-savers. Thanks a ton. I really appreciate your time and
effort.

Best regards,
Satadru
 
Top