Making a report open in front of all other open forms

C

cindyn

I am opening a report via VB code, using DoCmd.OpenReport. It works great,
but it always opens the report behind several other forms that may be open at
the time. I would like it to be opened in front of (on top of) everything
else that's open. All the forms and the report are NOT Popup or Modal.
Are there any options like this out there? I couldn't
find any.

I also thought to try forcing the focus to it, but
because it's doing it dynamically from a list box based on the currently
selected row (thus report) to open, I don't have a specific report name so I
can't figure out the syntax to SetFocus when you are using the .Value
property.

My code looks like this:

With Me!lstReportList
If IsNull(.Value) Then
MsgBox "Please select a report first!"
Else
'Open the selected report
DoCmd.OpenReport .Value, acViewPreview
'Close the select report form
DoCmd.Close acForm, "Report List", acSaveNo
' Set focus to the just opened report
'.Value SetFocus -- this is the syntax I can't figure out
End If
End With
 
A

Allen Browne

Try:
Reports(.Value).SetFocus
That's assuming the bound column of the list box contains the name of the
report.

The report should open with focus unless it is already open.
 
C

cindyn

I tried that... Report(.Value).SetFocus but now it compiles but I get an
error at that line at runtime that reads "Sub or Function not defined". I'm
using Access 2000, perhaps there is another syntax for this version?
 
A

Allen Browne

You missed the 's'.

You are referring to the Reports collection, and specifying a member by
name. It's like saying:
Reports("Report1").SetFocus
 
C

cindyn

I tried it with the s and I still get an error although a different one,
"Application-defined or object_defined error" at runtime. Another other
thoughts? I reall appreciate it.
 
A

Allen Browne

Assumptions:
- Your report is named "Report1". If not, replace "Report1" with the name of
your report.

- The report is already open.

If that's the case, you can debug your syntax by opening the Immediate
Window (Ctrl+G), and entering:
? Reports("Report1").Name
That should return the name of the report.

Once that is working, you can:
Reports("Report1").SetFocus

Once that is working, you can use the value of the list box to supply the
name of the report.
 
C

cindyn

I tested it with hard coding the report name of a specific report in the
syntax you specified below Reports("Report1").SetFocus and then made sure
to select Report1 as my choice at runtime but I still got the same error
"Application-defined or object_defined error" . I had to deliver it today so
I worked around it for now by closing some of the other forms first. I'll
check out some more tech docs and see if I can find out why this keeps
happening.

Thanks for all your help.
 

Ask a Question

Want to reply to this thread or ask your own question?

You'll need to choose a username for the site, which only take a couple of moments. After that, you can post your question and our members will help you out.

Ask a Question

Top