Link to home
Start Free TrialLog in
Avatar of LenaWood
LenaWood

asked on

Set Focus using Global Variable

This is an extension of this question:

https://www.experts-exchange.com/questions/21981827/Log-a-Report-as-being-printed.html

The solution given worked on one machine but not another one (grrr sometimes I just LOVE my job).  Anyway, seems I am going to have to use a global variable to do this.

Do I use the global variable to set the focus on the report that is open?  If so, how?  I have already created the variable and called it strReportName.  In the on open event of the report, I have:

strReportName = Me.Name

Now how do I use this?

I guess I could use it to print the report by using DoCmd.OpenReport strReportName - but since the report is already open, would that cause an issue?

Thanks in advance for your help!
Lena
ASKER CERTIFIED SOLUTION
Avatar of Rey Obrero (Capricorn1)
Rey Obrero (Capricorn1)
Flag of United States of America image

Link to home
membership
This solution is only available to members.
To access this solution, you must be a member of Experts Exchange.
Start Free Trial
Avatar of LenaWood
LenaWood

ASKER

I don't think Access 2000 doesn't use CurrentView.  I found this out when I tried using it before.  When I try to compile it on a 2000 machine I get a error saying it hasn't been declared (or something similar to that).

Any other way to check if it is open?  The only way it can be opened is in preview.

Lena
Thank you for the link.

I added this line to my code:

DoCmd.OpenReport strReportName, acViewNormal

and removed all the others.  This seems to make it work just like it should.

Thanks for your help - and again, thanks for the link.

Lena
Although it appears that your problem is resolved, I thought this was worth mentioning.  It seems that that utilizing the OnPrint event of the reports' headers may be a more elegant way of creating a print log:

Private Sub ReportHeader_Print(Cancel As Integer, PrintCount As Integer)
Dim rs As DAO.Recordset
Dim db As DAO.Database
   
    Set db = CurrentDb
   
    Set rs = db.OpenRecordset("tblReportLog")  
      rs.AddNew
              rs!PrintDate = Now()
              rs!DoneBy = Forms!frmUserInfo!UserName
              rs!ReportName = Application.Screen.ActiveReport.Name
      rs.Update
    rs.Close
    Set rs = Nothing

End Sub