I'm learning VBA on my own, so excuse my lack of expertise.
I'm trying to have message box pop up until a valid date is entered that will bring up file with that date in the name. And I want the message box to keep coming up until the user does input a valid date. Currently this code works if I put a valid date in the first time. If it is not a valid date the first time, the message box comes up, it doesn't open up the file regardless if it's a valid date or not on the 2nd input. I assume I would need some kind of a loop, but I'm having difficulty figuring it out with the With/IF/Then. Any help would be appreciated.
Sub InputBox()
Dim Message As String
Dim TitleBarTxt As String
Dim uResponse As String
Message = "Input the date which you want to update. The format must be YYYYMMDD."
TitleBarTxt = "Resource Planner"
uResponse = Application.InputBox(Message, TitleBarTxt)
With Application.FileSearch
.LookIn = "I:\Finance\Departments\Enrollment\History\"
.Filename = uResponse & "*.xls"
If .Execute > 0 Then
Workbooks.Open "I:\Finance\Departments\Enrollment\History\" & uResponse
Else: uResponse = Application.InputBox(Message,TitleBarTxt)
End If
End With
End Sub
I'm trying to have message box pop up until a valid date is entered that will bring up file with that date in the name. And I want the message box to keep coming up until the user does input a valid date. Currently this code works if I put a valid date in the first time. If it is not a valid date the first time, the message box comes up, it doesn't open up the file regardless if it's a valid date or not on the 2nd input. I assume I would need some kind of a loop, but I'm having difficulty figuring it out with the With/IF/Then. Any help would be appreciated.
Sub InputBox()
Dim Message As String
Dim TitleBarTxt As String
Dim uResponse As String
Message = "Input the date which you want to update. The format must be YYYYMMDD."
TitleBarTxt = "Resource Planner"
uResponse = Application.InputBox(Message, TitleBarTxt)
With Application.FileSearch
.LookIn = "I:\Finance\Departments\Enrollment\History\"
.Filename = uResponse & "*.xls"
If .Execute > 0 Then
Workbooks.Open "I:\Finance\Departments\Enrollment\History\" & uResponse
Else: uResponse = Application.InputBox(Message,TitleBarTxt)
End If
End With
End Sub