Results 1 to 3 of 3
  1. #1
    Ruegen's Avatar
    Ruegen is offline VIP
    Windows 7 64bit Access 2010 64bit
    Join Date
    Jul 2013
    Location
    Australia
    Posts
    1,496

    Add a year to a date from a combo box

    I have a date field where the user wants to put in only the day and month and not bother typing in the year and have it auto fill the year from the value of the combo box



    the combo box has year(date) in the second column(1)

    so basically I want a date variable stuffed with the year of the second column

    I was hoping to remove e.g. 2014 from the field then replace it with column value (2015)

  2. #2
    Ruegen's Avatar
    Ruegen is offline VIP
    Windows 7 64bit Access 2010 64bit
    Join Date
    Jul 2013
    Location
    Australia
    Posts
    1,496
    I am using

    Code:
    Dim selYear As Date
    
    
    selYear = Format(CDate("01/01/" & Me.CboYear.Column(1)), "dd/mm/yyyy")
    Debug.Print selYear & " date new"
    
    
    selYear = DateSerial(Year(selYear), Month(Me.txtFrom.Value), Day(Me.txtFrom.Value))
    Debug.Print selYear & " works"
    Me.txtFrom = selYear
    
    
    Debug.Print CStr(Year(selYear))
    Debug.Print Me.CboYear.Column(1)
    
    
    If CStr(Year(selYear)) <> Me.CboYear.Column(1) Then
    MsgBox "select a date from the same year you have selected!"
    Me.txtFrom.Value = Null
    End If
    and this works fine however if I format the textbox to "dd/mm" I get a problem

  3. #3
    Ruegen's Avatar
    Ruegen is offline VIP
    Windows 7 64bit Access 2010 64bit
    Join Date
    Jul 2013
    Location
    Australia
    Posts
    1,496
    Nevermind just used short date instead and it works fine, sorry guys.

Please reply to this thread with any new information or opinions.

Similar Threads

  1. Replies: 2
    Last Post: 04-25-2014, 11:33 PM
  2. Replies: 5
    Last Post: 12-11-2013, 08:15 AM
  3. Replies: 4
    Last Post: 01-09-2013, 11:16 AM
  4. Replies: 4
    Last Post: 01-10-2012, 06:26 PM
  5. Replies: 1
    Last Post: 12-09-2005, 10:29 PM

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts
  •  
Other Forums: Microsoft Office Forums