Tek-Tips is the largest IT community on the Internet today!

Members share and learn making Tek-Tips Forums the best source of peer-reviewed technical information on the Internet!

  • Congratulations John Tel on being selected by the Tek-Tips community for having the most helpful posts in the forums last week. Way to Go!

Need help with looping (I think)

Status
Not open for further replies.

AZGJC

Technical User
Sep 6, 2006
27
US
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

 
Message = "Input the date which you want to update. The format must be YYYYMMDD."
TitleBarTxt = "Resource Planner"
With Application.FileSearch
Do
uResponse = Application.InputBox(Message, TitleBarTxt)
.LookIn = "I:\Finance\Departments\Enrollment\History\"
.Filename = uResponse & "*.xls"
Loop Until .Execute > 0
End With
Workbooks.Open "I:\Finance\Departments\Enrollment\History\" & uResponse

Hope This Helps, PH.
Want to get great answers to your Tek-Tips questions? Have a look at FAQ219-2884 or FAQ181-2886
 
Thanks alot. It's seems so simple when I see the code written correctly!

AZGJC
 
Status
Not open for further replies.

Part and Inventory Search

Sponsor

Back
Top