2017-10-18 46 views
0

我有以下代碼,並被要求刪除用戶輸入框並自動提取文件。一個問題是,如果當天是星期一,我們需要將星期五的日期拉入(而不是昨天)。我很抱歉是非常基本的,但我相信我需要用之類的東西來代替InputBox("Input Date") - 但它不喜歡DayDD刪除用戶輸入框並用昨天的日期替換(自動化過程)

任何想法? (並感謝您的耐心與我提前)

DoCmd.SetWarnings False 
Dim InvDateStr As String 
Dim InvDate As Date 
Dim Directory_Sheets As String 
Dim filename_sheets As String 
Dim db As Database 
Dim rst As DAO.Recordset 
Dim startdate As Date 
Dim EndDate As Date 

'startdate = #9/23/2010# 
'enddate = #1/12/2011# 
'InvDate = startdate 

'Do Until InvDate = enddate 
InvDateStr = InputBox("Input Date") 
If InvDateStr = "" Then 
    Exit Sub 
End If 
InvDate = CDate(InvDateStr) 
Directory_Sheets = FilePath & "Inventory_Surveys\" 

On Error Resume Next 
' Pull Stores with Inventory 
+0

減用'使用DateAdd日(「d 「,-1,inputDate)' –

回答

1

我只打算做的日期部分,就可以實現它:

InvDate = Date - 1 'Yesterday 
Do While Weekday(InvDate, vbMonday) > 5 'Saturday or Sunday 
    InvDate = InvDate - 1 
Loop 
+0

Erik - 非常感謝你 - 工作。非常感激! – Erika