2017-05-09 76 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 

注:

請記住,只要該文件的文件夾中的計時器將永遠不會停止存在。