Solved

Set Focus to Report or Form

Posted on 2002-05-18
10
1,054 Views
Last Modified: 2012-08-13
I am having a little trouble when printing.  Because I have some code that occurs on timer from a main screen, sometime when printing, I print the main screen.  This is because the focus moves to the main screen while the code runs.  I know I can move the focus to a control, can I move the focus back to a form or report ?.
0
Comment
Question by:beams
[X]
Welcome to Experts Exchange

Add your voice to the tech community where 5M+ people just like you are talking about what matters.

  • Help others & share knowledge
  • Earn cash & points
  • Learn & ask questions
  • 4
  • 3
  • 2
  • +1
10 Comments
 
LVL 54

Expert Comment

by:nico5038
ID: 7019314
I would start with trying to get rid of the timer.
Do you really need it ?

Nic;o)
0
 
LVL 7

Expert Comment

by:Nosterdamus
ID: 7019653
Hi beams,

To set the focus to a form/report, you can use:
Forms![MyFormName]!ControlName.SetFocus
Where ControlName is a control (textbox, listbox, combobox, etc.) placed in the form/report.

BTW, Nico has a good point. If you can, deactivate the OnTimer before printting and activate it back again when printting is finnished.

HTH,

Nosterdamus
0
 

Author Comment

by:beams
ID: 7020559
I use the timer to check the database for new messages when in a network enviroment.  Is there another way to prompt a user on a network that he a message in the database.
0
Enterprise Mobility and BYOD For Dummies

Like “For Dummies” books, you can read this in whatever order you choose and learn about mobility and BYOD; and how to put a competitive mobile infrastructure in place. Developed for SMBs and large enterprises alike, you will find helpful use cases, planning, and implementation.

 
LVL 54

Expert Comment

by:nico5038
ID: 7020614
I can imagine that you offer the user a button or form to check by him self, but otherwise you could also create an e-mail to him, thus even showing there's something new when he's not working with the database.

I assume the database is also filled using access.
When you have MS-SQL it's even easier as you'll be able to place a trigger on a table update to send a mail. There has to be however a MAPI installed on the server.

Nic;o)
0
 

Author Comment

by:beams
ID: 7021357
A message box is displayed when the user gets a new message.  This all works very well because the actual message is also stored in the database.  I would like to keep the function but as I say the only problem I have is trying to find a way of ensuring the focus is back to the form or report after the timer event has finished.
0
 
LVL 7

Expert Comment

by:Nosterdamus
ID: 7021654
Hi beams,

If you are up to some coding, then you could consider the following method:
1. Declare a Global Variable (strCurrentFormReport).
2. You'll have to create some push/pop mechanism that will set the above variable to the actual form/report name to set focus to after the OnTimer event is done.
3. Every time you close a form/report, or open one, call a routine that will set the variable to the proper value.
4. Just before exitting the OnTimer event, use somethilng like:

Forms(strCurrentFormReport)!ControlName.SetFocus

HTH,

Nosterdamus
0
 

Author Comment

by:beams
ID: 7022874
This is what I do at the moment.  The problem is with reports, If I open the report with the Docmd, I cant determine if the report was being previewed or printed.


Private Sub Form_Timer()
On Error Resume Next

Dim tmpDiaryList As Long, LoadedReportName As String
Dim frmCurrentReport As Report, frmCurrentForm As Form
Set frmCurrentReport = Screen.ActiveReport
Set frmCurrentForm = Screen.ActiveForm
LoadedReportName = frmCurrentReport.Name

If IsLoaded("frmPaymentsNew") Or IsLoaded("Orders") Or IsLoaded("Quote") _
    Or IsLoaded("Orders All") Or IsLoaded("frmTaxRecDetails") Then
    DoCmd.OpenForm frmCurrentForm.Name
    Exit Sub
End If
If LoadedReportName <> "" Then
    Exit Sub
End If

On Error GoTo Err_Form_Timer
 
If Awarelist = 0 Then
    Awarelist = val(DCount("[Diary_ID]", "Diary Menu Union"))
End If

    tmpDiaryList = val(DCount("[Diary_ID]", "Diary Menu Union"))

    If val(Awarelist) <= val(tmpDiaryList) Then
        Awarelist = val(tmpDiaryList)
        Dim response As Integer
        response = MsgBox("You have New Messages, view your messages ?", 292, "MESSAGE CENTRE")
        If response = 6 Then
            DoCmd.OpenForm "Message Centre"
        End If
    End If

DoCmd.OpenForm frmCurrentForm.Name

Exit_Form_Timer:
    Exit Sub

Err_Form_Timer:
    MsgBox Err.Description
    Resume Exit_Form_Timer

End Sub
0
 
LVL 54

Expert Comment

by:nico5038
ID: 7024353
For this you could define a global variable in a module and set that before activating the form. In the form you can check that variable. (works only when reports are always triggered from VBA...)

Nic;o)
0
 
LVL 54

Expert Comment

by:nico5038
ID: 7222124

No comment has been added lately, so it's time to clean up this TA.
I will leave a recommendation in Community Support that this question is:
 - PAQ'd and pts removed
Please leave any comments here within the
next seven days.

PLEASE DO NOT ACCEPT THIS COMMENT AS AN ANSWER !

Nic;o)
0
 
LVL 5

Accepted Solution

by:
Netminder earned 0 total points
ID: 7240613
Per recommendation, points NOT refunded and question closed.

Netminder
CS Moderator
0

Featured Post

Enterprise Mobility and BYOD For Dummies

Like “For Dummies” books, you can read this in whatever order you choose and learn about mobility and BYOD; and how to put a competitive mobile infrastructure in place. Developed for SMBs and large enterprises alike, you will find helpful use cases, planning, and implementation.

Question has a verified solution.

If you are experiencing a similar issue, please ask a related question

In Part II of this series, I will discuss how to identify all open instances of Excel and enumerate the workbooks, spreadsheets, and named ranges within each of those instances.
Did you know that more than 4 billion data records have been recorded as lost or stolen since 2013? It was a staggering number brought to our attention during last week’s ManageEngine webinar, where attendees received a comprehensive look at the ma…
In Microsoft Access, learn the trick to repeating sub-report headings at the top of each page. The problem with sub-reports and headings: Add a dummy group to the sub report using the expression =1: Set the “Repeat Section” property of the dummy…
With Microsoft Access, learn how to start a database in different ways and produce different start-up actions allowing you to use a single database to perform multiple tasks. Specify a start-up form through options: Specify an Autoexec macro: Us…

763 members asked questions and received personalized solutions in the past 7 days.

Join the community of 500,000 technology professionals and ask your questions.

Join & Ask a Question