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

Auto fill date 1

Status
Not open for further replies.

mru

Technical User
May 26, 2002
20
GB
I dont know if this is possible or whether I have missed something very obvious but what I would like to do is this:

I have a date entry form for posting invoices, in order to speed up data entry I would like to be able to just enter the invoice date eg 5 and then when leaving the field get access to automatically change the invoice date to 05/10/02.
Sometimes invoices maybe from an earlier month and so it would still need to work as it does at the moment where by when I enter 23/9 it returns 23/09/02

also is it possible when first entering the date field to change the default date (created by autofillnewrecord mod) using the up and down arrows again helping to speed up data entry.

I've searched the forum and cant find anything like this which is why I'm wondering whether I've missed something obvious

Hope someone can help, thanks in advance

MRU
 
I wrote below Function to do similar task.Modify the code according to your requirement.

Public Function DateFormat(strDate As String) As Date
Dim intLen As Integer
Dim spMonth As String
Dim spYear As String
Dim spDate As String
Dim dtDate As Date
Dim sDate As String

If IsDate(strDate) Then
DateFormat = CDate(strDate)
Exit Function
End If
intLen = Len(strDate)
If intLen < 1 Then
'DateFormat = &quot;&quot;
Exit Function
End If
dtDate = Date
spMonth = CStr(Month(dtDate))
spYear = CStr(Year(dtDate))
Select Case intLen
Case Is <= 2
sDate = spMonth & &quot;/&quot; & strDate & &quot;/&quot; & spYear
Case 3
spDate = Right(strDate, 2)
spMonth = Left(strDate, 1)
sDate = spMonth & &quot;/&quot; & spDate & &quot;/&quot; & spYear
Case 4
spDate = Right(strDate, 2)
spMonth = Left(strDate, 2)
sDate = spMonth & &quot;/&quot; & spDate & &quot;/&quot; & spYear
Case 5
spMonth = Left(strDate, 1)
spDate = Mid(strDate, 2, 2)
spYear = Right(strDate, 2)
sDate = spMonth & &quot;/&quot; & spDate & &quot;/&quot; & spYear
Case 6
spMonth = Left(strDate, 2)
spDate = Mid(strDate, 2, 2)
spYear = Right(strDate, 2)
sDate = spMonth & &quot;/&quot; & spDate & &quot;/&quot; & spYear
Case Else
MsgBox &quot;Invalid Date Format.&quot;
DateFormat = Date
Exit Function
End Select

If IsDate(sDate) Then
DateFormat = CDate(sDate)
Else
MsgBox &quot;Invalid Date Format.&quot;
DateFormat = Date
End If
End Function Please remember to give helpful posts the stars they deserve!
This makes the post more visible to others in need!
 
Thanks for your reply essnrv, I copied your Function and tried to apply it to my form but I cant seem to get it to work.
All that happens when I enter 5 for instance is I get a message box saying ' The value entered isn't valid for this field'
I've tried calling the procedure from the afterupdate, on change and on exit events.
Ive tried removing the dd/mm/yy format but still cant get any joy.
Have you any idea what I may be doing wrong.
Thanks again
MRU
 
Is the control bound to a datafield ? If yes, I think It is difficult to do. Please remember to give helpful posts the stars they deserve!
This makes the post more visible to others in need!
 
If your control is databound, then unbind it and rebind to a new textbox with visible set to false. Use the code to change the value of the hidden textbox Let me know if this helps
________________________________________________________________
If you want to get the best response to a question, please check out FAQ222-2244 first

'There are 10 kinds of people in the world: those who understand binary, and those who don't.'
 
Thankyou essnrv and johnwm for your help,
Ive tried your suggestions but again unfortunately I cant get it to work.
I created a new unbound textbox (my intention being to copy the entered date to the bound 'datepurchased' field, which has been hidden, after the date has been formatted) now when i enter 5 the field just treats it as a number and changes nothing, if I set the format property to dd/mm/yy or mm/dd/yy I get a message saying ' the value entered isnt valid for this field'
Have you anymore ideas as to what Im doing wrong ?
Thanks again
MRU
 
Status
Not open for further replies.

Part and Inventory Search

Sponsor

Back
Top