Timer

D Willett
SilverLounger
Posts: 1728
Joined: 25 Jan 2010, 08:34
Location: Stoke on Trent - Staffordshire - England

Timer

Post by D Willett »

I have a timer (InactiveTimer.ctl) using the following code on my form:

Code: Select all

Private Sub itmrClose_UserInactive()
PDF1.Visible = True

If Dir("C:\Print - Confirmation.pdf") <> "" Then
   Me.AcrobatPath = "C:\Print - Confirmation.pdf"
   Me.PDF1.LoadFile Me.AcrobatPath
Else
   Me.AcrobatPath = "L:\MMPDF\Utilities\PDFViewer.pdf"
   Me.PDF1.LoadFile Me.AcrobatPath
End If
End Sub

Code: Select all

Private Sub Form_Load()
     
    itmrClose.InactiveInterval = 1000 * Val(txtInactiveSeconds.Text)
    itmrClose.Enabled = True

End Sub

Code: Select all

Private Sub Form_MouseDown(Button As Integer, Shift As Integer, X As Single, Y As Single)
itmrClose.Enabled = False
End Sub
It all works well with a hidden textcontrol set for 30 seconds.
Once the form is inactive for 30 seconds the code fires and loads the document, great because that's what I want it to do.
But the form carries on flashing, so I put "itmrClose.Enabled = False" after the event has fired.

Code: Select all

Private Sub itmrClose_UserInactive()
PDF1.Visible = True

If Dir("C:\Print - Confirmation.pdf") <> "" Then
   Me.AcrobatPath = "C:\Print - Confirmation.pdf"
   Me.PDF1.LoadFile Me.AcrobatPath
   [b]itmrClose.Enabled = False[/b]
Else
   Me.AcrobatPath = "L:\MMPDF\Utilities\PDFViewer.pdf"
   Me.PDF1.LoadFile Me.AcrobatPath
   [b]itmrClose.Enabled = False[/b]
End If
End Sub
But by doing this, the timer stays inactive and doesn't fire again ??
How can I fix this?
Cheers ...

Dave.

User avatar
HansV
Administrator
Posts: 78558
Joined: 16 Jan 2010, 00:14
Status: Microsoft MVP
Location: Wageningen, The Netherlands

Re: Timer

Post by HansV »

I don't understand - once the UserInactive event has occurred, you want the code to fire again but you also DON'T want it to fire again? :scratch:
Best wishes,
Hans

D Willett
SilverLounger
Posts: 1728
Joined: 25 Jan 2010, 08:34
Location: Stoke on Trent - Staffordshire - England

Re: Timer

Post by D Willett »

lol.... I always confuse........

The event needs to fire again and again and........... etc
The problem is once the event HAS fired, the form flashes until the user has activity again.
I falsed the event through the mouse as above, but that just kills the event going forward... :-)
Cheers ...

Dave.

User avatar
HansV
Administrator
Posts: 78558
Joined: 16 Jan 2010, 00:14
Status: Microsoft MVP
Location: Wageningen, The Netherlands

Re: Timer

Post by HansV »

I don't know the control that you mention, so the following is just a wild guess. Try replacing the line

Code: Select all

    itmrClose.Enabled = False
with

Code: Select all

    itmrClose.Enabled = False
    itmrClose.Enabled = True
and if that doesn't work, with

Code: Select all

    itmrClose.InactiveInterval = 0
    itmrClose.InactiveInterval = 1000 * Val(txtInactiveSeconds.Text)
Best wishes,
Hans

D Willett
SilverLounger
Posts: 1728
Joined: 25 Jan 2010, 08:34
Location: Stoke on Trent - Staffordshire - England

Re: Timer

Post by D Willett »

Hi Hans
Still got the flashing, I've gone back to the first version of code:
The form flashing is so annoying ??

Code: Select all

Private Sub Form_Load()
   
    itmrClose.InactiveInterval = 1000 * Val(txtInactiveSeconds.Text)
    itmrClose.Enabled = True

End Sub

Private Sub itmrClose_UserInactive()

PDF1.Visible = True

If Dir("C:\Print - Confirmation.pdf") <> "" Then

   Me.AcrobatPath = "C:\Print - Confirmation.pdf"
   Me.PDF1.LoadFile Me.AcrobatPath

Else

   Me.AcrobatPath = "L:\MMPDF\Utilities\PDFViewer.pdf"
   Me.PDF1.LoadFile Me.AcrobatPath

End If

End Sub

Private Sub Form_MouseDown(Button As Integer, Shift As Integer, X As Single, Y As Single)

itmrClose.Enabled = True
End Sub
Cheers ...

Dave.

User avatar
HansV
Administrator
Posts: 78558
Joined: 16 Jan 2010, 00:14
Status: Microsoft MVP
Location: Wageningen, The Netherlands

Re: Timer

Post by HansV »

Couldn't you ditch the entire timer?
Best wishes,
Hans

D Willett
SilverLounger
Posts: 1728
Joined: 25 Jan 2010, 08:34
Location: Stoke on Trent - Staffordshire - England

Re: Timer

Post by D Willett »

? Don't know ?

I'm loading an info doc on the forms inactivity, is there another way?
Cheers ...

Dave.

User avatar
HansV
Administrator
Posts: 78558
Joined: 16 Jan 2010, 00:14
Status: Microsoft MVP
Location: Wageningen, The Netherlands

Re: Timer

Post by HansV »

What I meant is, do you *really* need to load a document if the form is inactive?
Best wishes,
Hans

D Willett
SilverLounger
Posts: 1728
Joined: 25 Jan 2010, 08:34
Location: Stoke on Trent - Staffordshire - England

Re: Timer

Post by D Willett »

Unfortunately yes :-(
We have an info sheet which changes all the time giving workshop guy's current job tasks etc.
The theory of it is great, getting it to work is another thing ?
Cheers ...

Dave.

User avatar
HansV
Administrator
Posts: 78558
Joined: 16 Jan 2010, 00:14
Status: Microsoft MVP
Location: Wageningen, The Netherlands

Re: Timer

Post by HansV »

Does this help?

Code: Select all

Private Sub itmrClose_UserInactive()
    Static d As Date
    If Now > DateAdd("s", Val(txtInactiveSeconds.Text), d) Then
        PDF1.Visible = True
        If Dir("C:\Print - Confirmation.pdf") <> "" Then
            Me.AcrobatPath = "C:\Print - Confirmation.pdf"
        Else
            Me.AcrobatPath = "L:\MMPDF\Utilities\PDFViewer.pdf"
        End If
        Me.PDF1.LoadFile Me.AcrobatPath
        d = Now
    End If
End Sub
Best wishes,
Hans

D Willett
SilverLounger
Posts: 1728
Joined: 25 Jan 2010, 08:34
Location: Stoke on Trent - Staffordshire - England

Re: Timer

Post by D Willett »

I'll try it on Monday Hans , but I see what it does, hopefully it could be the answer.
Have a great weekend.
Cheers ...

Dave.

D Willett
SilverLounger
Posts: 1728
Joined: 25 Jan 2010, 08:34
Location: Stoke on Trent - Staffordshire - England

Re: Timer

Post by D Willett »

Morning Hans

This works great. I've set the txtInactiveSeconds to 60. The form does still flash but only once every 60 seconds which is totally acceptable.
Once again, many thanks.
Cheers ...

Dave.

User avatar
HansV
Administrator
Posts: 78558
Joined: 16 Jan 2010, 00:14
Status: Microsoft MVP
Location: Wageningen, The Netherlands

Re: Timer

Post by HansV »

The flash is because the PDF file is loaded again so that the user sees the latest version.
Best wishes,
Hans

D Willett
SilverLounger
Posts: 1728
Joined: 25 Jan 2010, 08:34
Location: Stoke on Trent - Staffordshire - England

Re: Timer

Post by D Willett »

:evilgrin: Good thinking Batman.
Cheers ...

Dave.

D Willett
SilverLounger
Posts: 1728
Joined: 25 Jan 2010, 08:34
Location: Stoke on Trent - Staffordshire - England

Re: Timer

Post by D Willett »

Just a thought Hans.

I've set this up now to look for the following file:

If Dir("L:\Mmpdf\Workshop\DAILYWS.pdf") <> "" Then
Me.AcrobatPath = "L:\Mmpdf\Workshop\DAILYWS.pdf"
Else
Me.AcrobatPath = "L:\MMPDF\Utilities\PDFViewer.pdf"

I tried to use *.pdf in the workshop folder which returns a blank doc in the pdf control.

If Dir("L:\Mmpdf\Workshop\*.pdf") <> "" Then
Me.AcrobatPath = "L:\Mmpdf\Workshop\*.pdf"
Else
Me.AcrobatPath = "L:\MMPDF\Utilities\PDFViewer.pdf"

I'm just anticipating a user not spelling "DAILYWS" correctly ?
Cheers ...

Dave.

User avatar
HansV
Administrator
Posts: 78558
Joined: 16 Jan 2010, 00:14
Status: Microsoft MVP
Location: Wageningen, The Netherlands

Re: Timer

Post by HansV »

Try

Code: Select all

If Dir("L:\Mmpdf\Workshop\*.pdf") <> "" Then
    Me.AcrobatPath = Dir("L:\Mmpdf\Workshop\*.pdf")
Else
    Me.AcrobatPath = "L:\MMPDF\Utilities\PDFViewer.pdf"
End If
Best wishes,
Hans

D Willett
SilverLounger
Posts: 1728
Joined: 25 Jan 2010, 08:34
Location: Stoke on Trent - Staffordshire - England

Re: Timer

Post by D Willett »

It's not liking it Hans, just returns the "PDFViewer.pdf" file.
Don't worry, it's not a major problem.

Many Regards
Cheers ...

Dave.

User avatar
HansV
Administrator
Posts: 78558
Joined: 16 Jan 2010, 00:14
Status: Microsoft MVP
Location: Wageningen, The Netherlands

Re: Timer

Post by HansV »

Try single-stepping through the code to see what happens if there is a pdf file in L:\Mmpdf\Workshop.
Best wishes,
Hans