Date input format

R

Roy Gudgeon

Hi Guys

I have a date entry form.
One box requires a date.

I have several users using the form, each types the date in a different way.

I would like a consistant dd/mm/yyyy format. I know that access allows an
input mask to be set, can this be done in a text box on a data entry form ?

thanks
Roy
 
J

Jacob Skaria

Why dont you use the calendar control or a DT Picker... OR if you dont have
these controls you can build one...


You could build one. In a fresh UserForm place a textbox (TextBox1) and try
pasting the below code ...Use up/down arrows to adjust the time


Private Sub UserForm_Activate()
Me.TextBox1 = Format(Now, "dd/mm/yyyy")
End Sub
Private Sub TextBox1_KeyDown(ByVal KeyCode As MSForms.ReturnInteger, ByVal
Shift As Integer)
'Date and Time Picker Use down/up arrow to change date/time.
Dim intPos As Integer, strType As String
If KeyCode = 38 Or KeyCode = 40 Then
intPos = Me.TextBox1.SelStart
strType = Application.Lookup(intPos, Array(0, 3, 6), Array("d", "m", "yyyy"))
Me.TextBox1 = Format(DateAdd(strType, (39 - KeyCode), TextBox1), "dd/mm/yyyy")
KeyCode = 0
Me.TextBox1.SelStart = intPos
End If
End Sub
 
R

Roy Gudgeon

Hi Jacob

thanks for reply

am struggling a bit with this (probably beyond my abilities !)
isthere another way without date picker or something I can insert into
existing code fo rthe text box on the form ?
 

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