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

set Date format in Me.txtstartdate

Status
Not open for further replies.

sonikudi

Technical User
Sep 9, 2007
81
0
0
US
hey guys,

How can i set the format of my date to mm/dd/yy in the properties of my text box itself...i have a start date box and an end date box. and if the user doesn't enter the right format in say the start box then i would want an error to pop up before the user moved to the end date..To do this:

1) What property of the text box would i have to write my code in?and
2) what is the VB procedure or function to set the format to mm/dd/yy..

P.S: because each of these forms are used for several purposes i don't want to write the code in a user event procedure as that will involve me changing code for several combining events that call this form as well as other forms with date text boxes.


Thank you for any help.
 
You could write code in the after update event of the text box like:
Code:
If Not IsDate(Me.txtDate) Then
    Msgbox "PEBKAC, try again", vbOkOnly, "Error"
End If
You can add more code to set the value to null or whatever.

I would just set the format property to what you want.

Duane MS Access MVP
Now help me support United Cerebral Palsy
 
if i put the code under the After Update column then my error messege shows up only if a user initiates an event like hit the 'cancel' button or hit the 'okay' button..however the access error comes up if i move to the next textbox , and i think thats because i specified the format in the textbox properties.

 
The code will run whenever the text box loses focus. What do you want to happen? If you want ultimate control, disable the text box and use a calendar form for entry.

Duane MS Access MVP
Now help me support United Cerebral Palsy
 
actually on a second thought..thats works fine...i didn't even have to write the code you gave. Just entering the format for text box under properties as mm/dd/yy..worked fine...

thanks.
 
Status
Not open for further replies.

Part and Inventory Search

Sponsor

Back
Top