|
-
Jul 21st, 2003, 08:51 AM
#1
Thread Starter
PowerPoster
Auto Fill Date
I want to be able to auto fill a text box that holds a date depending on what is entered. All is working OK except when I try to auto fill when only the day has been entered. If only the day is entered (d or dd) the auto fill doesn't work. Below is the code i'm using. Can anyone offer any suggestions?
Code:
Private Sub txtDate_LostFocus()
Dim DayOnly As String
If txtDate = Format(txtDate, "dd/mm/yyyy") Or txtDate = Format(txtDate, "dd/mm/yy") _
Or txtDate = Format(txtDate, "d/mm/yyyy") Or txtDate = Format(txtDate, "d/mm/yy") _
Or txtDate = Format(txtDate, "dd/m/yyyy") Or txtDate = Format(txtDate, "dd/m/yy") _
Or txtDate = Format(txtDate, "d/m/yyyy") Or txtDate = Format(txtDate, "d/m/yy") Then
txtDate = Format(txtDate, "d/mm/yyyy")
ElseIf txtDate = Format(txtDate, "dd") Or txtDate = Format(txtDate, "d") Then
DayOnly = txtDate
txtDate = DayOnly & "/" & CurrentMonth & "/" & CurrentYear
txtDate = Format(txtDate, "d/mm/yyyy")
ElseIf txtDate = Format(txtDate, "d/m") Or txtDate = Format(txtDate, "dd/m") _
Or txtDate = Format(txtDate, "d/mm") Or txtDate = Format(txtDate, "dd/mm") Then
DayOnly = txtDate
txtDate = DayOnly & "/" & CurrentYear
txtDate = Format(txtDate, "d/mm/yyyy")
End If
End Sub
-
Jul 21st, 2003, 09:53 AM
#2
Frenzied Member
Maybe VB doesn't think that "12" is a formatted date. Maybe it thinks that it is just a number.....
-
Jul 21st, 2003, 11:35 AM
#3
Addicted Member
try the following code and reply
Private Sub txtDate_LostFocus()
Dim DayOnly As String
If txtDate = Format(txtDate, "dd/mm/yyyy") Or txtDate = Format(txtDate, "dd/mm/yy") _
Or txtDate = Format(txtDate, "d/mm/yyyy") Or txtDate = Format(txtDate, "d/mm/yy") _
Or txtDate = Format(txtDate, "dd/m/yyyy") Or txtDate = Format(txtDate, "dd/m/yy") _
Or txtDate = Format(txtDate, "d/m/yyyy") Or txtDate = Format(txtDate, "d/m/yy") Then
txtDate = Format(txtDate, "d/mm/yyyy")
'ElseIf txtDate = Format(txtDate, "dd") Or txtDate = Format(txtDate, "d") Then
'DayOnly = txtDate
'txtDate = DayOnly & "/" & Month(Now) & "/" & Year(Now)
'txtDate = Format(txtDate, "d/mm/yyyy")
ElseIf txtDate = Format(txtDate, "d/m") Or txtDate = Format(txtDate, "dd/m") _
Or txtDate = Format(txtDate, "d/mm") Or txtDate = Format(txtDate, "dd/mm") Then
DayOnly = txtDate
txtDate = DayOnly & "/" & Year(Now)
txtDate = Format(txtDate, "d/mm/yyyy")
ElseIf Len(txtDate) <= 2 Then
DayOnly = txtDate
txtDate = DayOnly & "/" & Month(Now) & "/" & Year(Now)
'txtDate = Format(txtDate, "d/mm/yyyy")
End If
End Sub
-
Jul 21st, 2003, 09:35 PM
#4
Thread Starter
PowerPoster
Thanks senthilkbs. That did the job.
Posting Permissions
- You may not post new threads
- You may not post replies
- You may not post attachments
- You may not edit your posts
-
Forum Rules
|
Click Here to Expand Forum to Full Width
|