Input Mask (or is there a better way)

K

Karen

I have a text box (expiration date) on a form and I want users to enter
data in that text box in a certain manner (ie: 01-2010). I would also
like them to be able to enter 'STABLE' if there is not an expiration
date. I currently have an input mask set on the properties of that
control (00\-0000;0;_) but it doesn't allow the entry of anything
except a date in that format.

Any ideas of what I can do to do this?

Karen S.
 
B

Bill Mosca, MS Access MVP

There is no way to use an Input Mask and allow non-compliant text as well.
What you could do is check the value in the BeforeUpdate event to see if it
matches one or the other.

Here is what the sub would look like:


Private Sub txtExpireDate_BeforeUpdate(Cancel As Integer)
If Me.txtExpireDate <> "STABLE" _
And (IsNumeric(Left(txtExpireDate, 2)) = False _
Or Mid(txtExpireDate, 3, 1) <> "-" _
Or IsNumeric(Right(txtExpireDate, 4)) = False _
Or IsDate(txtExpireDate) = False) Then
MsgBox "Please enter date as mm-yyyy or enter 'STABLE'"
Cancel = -1
End If
End Sub

I think I got everything.
 

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

Similar Threads


Top