Inputbox and vbcancel

R

RC

Hello, I have the following code.

InputVal2 = InputBox(Prompt:="Please enter macro start date in MM/DD/
YY format" _
, Title:="Starting Date Entry", _
Default:=(DateFormat(ActiveProject.CurrentDate,
pjDate_mm_dd_yy)))

If InputVal2 < ActiveProject.ProjectStart Then
MsgBox "Starting date is before Project Start, macro
ending"
Exit Sub
ElseIf InputVal2 = False Then
MsgBox "Starting date entry cancelled by user, macro
ending"
Exit Sub

Else
InputDate = CDate(InputVal2)
End If

I keep getting a "Type Mismatch" error when I click the "Cancel"
button. The value of InputVal2 always seems to be equal to 12:00:00
AM. I thought that hitting Cancel in the Inputbox would either return
0 or False, I've tried both. Any advice?

Thank you!
 
J

Jan De Messemaeker

Hi,

InputVal2 is probably declared as date so the returning value is converted
into a date value.
Natively hitting x or cancel returns a Null String but by assigning that to
a variable other than a string it is converted.
Hope this helps,
 

Ask a Question

Want to reply to this thread or ask your own question?

You'll need to choose a username for the site, which only take a couple of moments. After that, you can post your question and our members will help you out.

Ask a Question

Top