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 TouchToneTommy on being selected by the Tek-Tips community for having the most helpful posts in the forums last week. Way to Go!

Why will this not work? Egads!

Status
Not open for further replies.
Aug 2, 2000
325
US
I am calling this from the expression builder as = getDate()

Sub getDate()
Dim theDate As Date
Dim strInput As String
Dim strMsg As String
theDate = Format(Now() - 1, "mm/dd/yy")
strMsg = "Please Enter the date, format = mm/dd/yy"
strInput = InputBox(Prompt:=strMsg, Title:="HEY!", Default:=theDate)
End Sub

It seems to work but when I press enter I get an error.
Any help would help a heap.
Dave
 
Hi Dave, I just tried below and it works fine for me! :)

Sub getDate()
Dim theDate As Date
Dim strInput As String, strMsg As String
theDate = Date - 1
theDate = Format(theDate, "mm/dd/yy")
strMsg = "Please Enter the date in the format ''mm/dd/yy''"
strInput = InputBox(Prompt:=strMsg, Title:="HEY!", Default:=theDate)
End Sub Gord
ghubbell@total.net
 
Are you trying to return strInput back as a variable. Then you should define the variable in the top line:
Sub getDate() (strInput as Date)
I think that syntax is correct. Others with more expertise feel free to correct me.
And it makes me wonder... what's the difference between that and a function, as in
Function getDate() (strInput as Date)
????
 
Thanks, both seem to be correct. I really only needed to define as a funtion rather than a sub. It didn't like the (strInput as Date)or string, next to the Function getDate.
 
Actually, I see now I that stuck in an extra set of parens. Duh!(slaps forehead)
 
Yes, but WHY? This doesn't "Rate" a function, it could easily be just 'in-lined'. Would be somewhat more efficient, and clearer to the user.


MichaelRed
redmsp@erols.com

There is never time to do it right but there is always time to do it over
 
by "rate" I mean it is not "worth the effort" to place this in a seperate procedure. It should just me inclided "inline" (e.g. as one or more LINES OF CODE) in the proccedure which would call it. Each reference to a procedure causes VB (and most "languages") to instantiate a number of items. These take time and memory. Using these resources for really trivial procedures isn't (IMHO) good pratctice.
MichaelRed
redmsp@erols.com

There is never time to do it right but there is always time to do it over
 
Status
Not open for further replies.

Part and Inventory Search

Sponsor

Back
Top