Results 1 to 4 of 4
  1. #1
    Join Date
    Jan 2009
    Posts
    1

    date manipulation

    after i enter a date into a date field (format mm/dd/yyyy) i'd like text box on the same form to respond with the month name and year. for example: i enter 1/1/2009 and the text box should respond January 2009. thanks in advance.

  2. #2
    Join Date
    May 2008
    Posts
    5

    Red face

    Greetings, try this. I have a form with 2 textboxes on it. on the box that will get the date, I set the input mask to "00/00/0000" then on the exit event of that same box I put this sub:

    Private Sub Text2_Exit(Cancel As Integer)
    Dim dtPartYear
    Dim dtPartMonth

    'grab the year
    dtPartYear = Right(Text2.Value, 4)

    'use select case to get the month (first 2 digits) and then test for value
    Select Case Left(Text2.Value, 2)
    Case Is = "01"
    dtPartMonth = "January"
    Case Is = "02"
    dtPartMonth = "Febuary"
    End Select

    'assign to the other text box
    Text0.Value = dtPartMonth & " " & dtPartYear
    End Sub

    try it let me know. Works for me. Notice! you will need to do some error checking here though!

    O

  3. #3
    Huddle is offline Competent Performer
    Windows XP Access 2003
    Join Date
    Jun 2010
    Posts
    318

    Need More Info

    I only need the month to show in the 2nd field(Month). I've entered the Event as below. If I add "Cancel as Integer" then it give me an error. If I remove that part then it runs but does not populate the 2nd field. What am I missing?


    Private Sub DateNotified_AfterUpdate()
    Dim dtPartMonth
    Select Case Left(DateNotified.Value, 2)
    Case Is = "01"
    dtPartMonth = "Jan"
    Case Is = "02"
    dtPartMonth = "Feb"
    Case Is = "03"
    dtPartMonth = "Mar"
    End Select
    Month.Value = dtPartMonth

    End Sub

  4. #4
    ssanfu is offline Master of Nothing
    Windows 2K Access 2000
    Join Date
    Sep 2010
    Location
    Anchorage, Alaska, USA
    Posts
    9,664
    Quote Originally Posted by Huddle View Post
    I only need the month to show in the 2nd field(Month). I've entered the Event as below. If I add "Cancel as Integer" then it give me an error. If I remove that part then it runs but does not populate the 2nd field. What am I missing?


    Private Sub DateNotified_AfterUpdate()
    Dim dtPartMonth
    Select Case Left(DateNotified.Value, 2)
    Case Is = "01"
    dtPartMonth = "Jan"
    Case Is = "02"
    dtPartMonth = "Feb"
    Case Is = "03"
    dtPartMonth = "Mar"
    End Select
    Month.Value = dtPartMonth

    End Sub

    "Month" is a reserved word (and a built in function) in Access and shouldn't be use as object names.

    Here is a list of reserved words in Access:

    http://allenbrowne.com/AppIssueBadWord.html


    i'd like text box on the same form to respond with the month name and year. for example: i enter 1/1/2009 and the text box should respond January 2009.
    Have the after update event of the "DateNotified" text box set the date of the 2nd text box to the same date.
    Then, in the 2nd text box properties, in the FORMAT tab, set the Format property to "mmmm yyyy" (no quotes)

    No code, no fuss.

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

Similar Threads

  1. Query manipulation using VBA
    By benattal in forum Programming
    Replies: 0
    Last Post: 12-31-2008, 09:12 AM
  2. 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