Date Validation

G

Guest

I have a form bound to a table.One of the textbox is bound to a date field.
currently I have no validation rules. I only format the date to "mm-dd-yyyy"
format in the format properties of the textbox. Some of users are entering
wrong data like 12-10-205". How could I enforce the validation rule for this
textbox? Please explain.

CC
 
G

Guest

Open your form in design mode.
Select the data control.
Select Input Mask
Use the wizard and select "short date"
 
G

Guest

Followup: what happens when a user enters a unbound Short Date (format &
input mask) control by clicking in the middle instead of pressing Tab to get
there? Depending on where the user clicks, the user can begin typing the date
in the wrong part of the box.

Thus, an attempt to type this: 12/17/05 (with the "/" coming from the mask)
Could result in this: " / 1/27" if the user clicked before the third
position and began typing. To avoid much of this, I already use this:

DateBox_CLick()
With DateBox
.SelStart = 0
.SelLength = Len(.Text)
End With
End sub

However, there is nothing I can do to prevent a user from entering the
control, then pressing the right arrow key, and beginning to type. What
validation rule would I use to prevent the error that is generated if the
user enters non-date information in the field?

I know I could just use this: >=#1/1/1900#. Is there a simpler way that
actually deals with a valid date and not with a date range operator?

I guess what I need to know is how to use IsDate in a validatoin rule.
 
A

Arvin Meyer [MVP]

I guess what I need to know is how to use IsDate in a validatoin rule.

I know of no way to use IsDate in a Validation Rule, but the good news is
that you can code much more complex validation rules in a control's
BeforeUpdate event. So, you, use something like (aircode):

Sub txtMyControl_BeforeUpdate(Cancel As Integer)
If Not IsDate(Me.txtMyControl) Then
MsgBox "Sorry Bub, you messed up", vbOKOnly, "No banana!"
Me.txtMyControl.Undo
Cancel = True
End If
End Sub
--
Arvin Meyer, MCP, MVP
Microsoft Access
Free Access downloads
http://www.datastrat.com
http://www.mvps.org/access
 
G

Guest

Thanks. I just thought there might be some way to avoid that bit of VBA code
by using a validation rule. I guess I'll just stick with VBA.
 
G

Guest

Thanks. I am currently trapping errors for every sub in my apps & handing off
the error to a global function that provides a custom "This is not the
correct data type" message for the user on the 2113 error that is generated
in this case.

I was just hoping to find a way to embed this process in a Validation rule.
I was hoping for something like this: "Like #_#" - something that would just
ensure that the result was a date.
 

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