Results 1 to 4 of 4

Thread: Auto Fill Date

  1. #1

    Thread Starter
    PowerPoster lintz's Avatar
    Join Date
    Mar 2003
    Location
    The 19th Hole
    Posts
    2,697

    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

  2. #2
    Frenzied Member
    Join Date
    Jan 2001
    Location
    Newbury, UK
    Posts
    1,878
    Maybe VB doesn't think that "12" is a formatted date. Maybe it thinks that it is just a number.....

  3. #3
    Addicted Member
    Join Date
    Jan 2002
    Posts
    144

    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

  4. #4

    Thread Starter
    PowerPoster lintz's Avatar
    Join Date
    Mar 2003
    Location
    The 19th Hole
    Posts
    2,697
    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
  •  



Click Here to Expand Forum to Full Width