2017-05-09 81 views
-2

我是VBA和MS Access的新手,请耐心等待。MS Access倒数计时器更新和文件夹触发器

我正在寻找倒数计时器,每次在特定文件夹中添加或创建新文件时都会触发倒数计时器。

它应该从7分钟开始,并运行到0.如果新文件已被添加/创建,计时器应该返回到07:00并重做该过程。

我的时钟计时器现在只能手动:

Option Compare Database 
Option Explicit 

Private Sub Command4_Click() 
    Me.TimerInterval = 1000 
    Me.Text2 = Me.Text0 
End Sub 

Private Sub Form_Timer() 
    If Format(Me.Text2, "hh:nn:ss") = #12:00:00 AM# Then 
     MsgBox "Time is up" 
     Me.TimerInterval = 0 
    Else 
     Me.Text2 = DateAdd("s", -1, Me.Text2) 
    End If 
End Sub 

感谢您的阅读和提前的所有帮助。

+0

看看'filesystemobject' –

+0

filesystemobject? @Nathan_Sav。对不起,我不能关注 – Zaynqx

+0

使用谷歌了解它:) –

回答

0

这对我来说不是很清楚你想达到什么目的。

但是,您可以在上启动计时器,并每5秒检查文件是否存在,直到达到7分钟截止点。

如果找到该文件,重置计时器或在达到7分钟时结束计时。

Private Const max_ As Long = 420 '7 min/420 seconds 
Private counter_ As Long   'Counter 
Private file_ As String    'File to look for 

'Load 
Private Sub Form_Load() 
    file_ = "YourFilePath"   'Use *.* for any file 
    Me.TimerInterval = 5000   '5 seconds - change to whatever you like 
End Sub 

'Timer 
Private Sub Form_Timer() 
    If Len(Dir(file_)) = 0 Then 
     'Nothing found 
     If counter_ < max_ Then 
      counter_ = counter_ + 5 'Keep counting - increment must match TimerInterval 
     Else 
      Me.TimerInterval = 0  'End 
      counter_ = 0 
     End If 
     Exit Sub 
    End If 

    'File found - do you action 

    'Reset counter or End 
    counter_ = 0 
End Sub 

注:

请记住,只要该文件的文件夹中的计时器将永远不会停止存在。