Help with boolean type missmatch error (VBA, Userform, vbnullstring)

Engineer1279

New Member
Joined
Feb 28, 2013
Messages
19
OK, so I have a userform with some text boxes that I have specially formatted to accept only date values in the form of mm/dd/yy. By default they are blank. I have a check in one of my codes that looks like this

Code:
If DateBox <> vbNullString And DateValue(DateBox) > checkdate Then
  M1 = "NEOPRENE" & Chr(13)
Else
  M1 = "" & Chr(13)
End If

Where DateBox is this specially formatted TextBox and checkdate is a future date being checked against.
So if DateBox has a value in it AND that value is greater than the date being checked against the returend string is Neoprene, otherwise it is blank.

Well the problem I have is when the first condition returns FALSE, i.e. when DateBox is empty, the DateValue half still gets evaluated and returns a type missmatch error or something like that because DateValue("") returns an error. I have line of code 8 times, one for Neoprene, squeegee, etc. So the name of the text boxes are each unique and I am using M1, M2, M3, etc. I could probably nest the seond condition in a conditional of its own below the first condition, but I want to avoid that. It seems like there is a simple answer to this problem that I am missing.

For other reasons, use of "On Error Resume Next" doesn't work for this situation because it causes a result opposite to what I want to happen. So anyway, if someone could help resolve this for me I would appreciate it.
 

Excel Facts

What do {} around a formula in the formula bar mean?
{Formula} means the formula was entered using Ctrl+Shift+Enter signifying an old-style array formula.

Forum statistics

Threads
1,203,203
Messages
6,054,117
Members
444,703
Latest member
pinkyar23

We've detected that you are using an adblocker.

We have a great community of people providing Excel help here, but the hosting costs are enormous. You can help keep this site running by allowing ads on MrExcel.com.
Allow Ads at MrExcel

Which adblocker are you using?

Disable AdBlock

Follow these easy steps to disable AdBlock

1)Click on the icon in the browser’s toolbar.
2)Click on the icon in the browser’s toolbar.
2)Click on the "Pause on this site" option.
Go back

Disable AdBlock Plus

Follow these easy steps to disable AdBlock Plus

1)Click on the icon in the browser’s toolbar.
2)Click on the toggle to disable it for "mrexcel.com".
Go back

Disable uBlock Origin

Follow these easy steps to disable uBlock Origin

1)Click on the icon in the browser’s toolbar.
2)Click on the "Power" button.
3)Click on the "Refresh" button.
Go back

Disable uBlock

Follow these easy steps to disable uBlock

1)Click on the icon in the browser’s toolbar.
2)Click on the "Power" button.
3)Click on the "Refresh" button.
Go back
Back
Top