Tek-Tips is the largest IT community on the Internet today!

Members share and learn making Tek-Tips Forums the best source of peer-reviewed technical information on the Internet!

  • Congratulations Mike Lewis on being selected by the Tek-Tips community for having the most helpful posts in the forums last week. Way to Go!

Report is not getting focus

Status
Not open for further replies.

missyu

Programmer
Jan 29, 2001
13
0
0
CA
Hope someone can help me.

I've done this a million times but for some reason, it's not working. My code:
*************************************************
Private Sub cmdOK_Click()
If DCount("*", "qryRptAppsPerDept") = 0 Then
MsgBox "No data to report", vbInformation, "REPORT"
Else
DoCmd.OpenReport "rptAppsPerDept", acViewPreview
DoCmd.Close acForm, "frmReportMenu"
End If
End Sub
*************************************************

The report is generated but the focus gets set back to my main screen. Why is this happening? This is the exact code I've used before and I've never had this problem. Note, my main screen is a form with a subform on it.

Thanks.

missyu
 
Hello Missyu,

Try a small test here:

Private Sub cmdOK_Click()
If DCount("*", "qryRptAppsPerDept") = 0 Then
MsgBox "No data to report", vbInformation, "REPORT"
Else
DoCmd.Close acForm, "frmReportMenu"
DoCmd.OpenReport "rptAppsPerDept", acViewPreview
End If
End Sub

In your reports On Open Event:
DoCmd.Maximize

Might solve your prob....


Gord
ghubbell@total.net
 
Thanks Gord,
But that did not work. The reason I don't close the form until after I open the report is because the form is passing values to the report. By closing the form and then opening the report, the report runs and then the dialogue box looking for parameters doesn't open up.

The way I have it, actually generates the report but the user has to go to Window (in the menu bar) and select the report. So it is there but it is hidden by my main screen. I know, it's driving me crazy!
 
Ok...here's a method I use a lot:

Private Sub cmdOK_Click()
If DCount("*", "qryRptAppsPerDept") = 0 Then
MsgBox "No data to report", vbInformation, "REPORT"
Else
DoCmd.minimize '<-
DoCmd.OpenReport &quot;rptAppsPerDept&quot;, acViewPreview
End If
End Sub

Add this function to a new Module only if you don't already have it:

Function IsLoaded(ByVal strFormName As String) As Integer
' Returns True if the specified form is open in Form view or Datasheet view.
Const conObjStateClosed = 0
Const conDesignView = 0
If SysCmd(acSysCmdGetObjectState, acForm, strFormName) <> conObjStateClosed Then
If Forms(strFormName).CurrentView <> conDesignView Then IsLoaded = True
End If
End Function


Now on your reports &quot;On close&quot; event add:

On Error Resume Next
If IsLoaded(&quot;NameOfYourForm&quot;) Then
Forms![NameOfYourForm].SetFocus
DoCmd.Restore
End If

Keep the DoCmd.maximize thing in your report on open...

Try this for fun and watch what happens! I'll stay tuned.
Gord
ghubbell@total.net
 
Status
Not open for further replies.

Part and Inventory Search

Sponsor

Back
Top