Results 1 to 10 of 10
  1. #1
    Rameez is offline Advanced Beginner
    Windows XP Access 2003
    Join Date
    Jun 2009
    Location
    Chennai, India
    Posts
    40

    Problem with date field...

    Look through the examples...you will understand my problem.




    Sub testdate(t1 As Date)
    Dim s As Integer
    t1 = Format(t1, "mm/dd/yy")
    Debug.Print t
    s = DatePart("m", t1)
    Debug.Print s
    End Sub

    Call testdate(06/19/2009)
    is giving 12
    Call testdate(#06/19/2009#)

    is giving 06....(correct value)

    In my code, I have to extract the month and year part from cs4
    Function IsDupeslam(cs1 As String, cs2 As String, cs3 As String, cs4 as date)
    Dim y As Integer
    y = DatePart("m", cs4)

    debug.print y
    End Function
    obiviously the above code gives wrong result....
    The solution i think will be to put the leading and trailing # to the date field...

    Function dater11(d1 As Date)
    Dim m1 As Integer
    Debug.Print d1
    m1 = Month(" & # d1 # &")...this code is to be corrected....
    Debug.Print m1
    End Function


    Please help

  2. #2
    marianne is offline Competent Performer
    Windows XP Access 2003
    Join Date
    Mar 2009
    Location
    Asia Pacific Region
    Posts
    150
    Sub testdate(t1 As Date)
    Dim s As Integer
    t1 = Format(t1, "mm/dd/yy")
    Debug.Print t1
    s = DatePart("m", t1)
    MsgBox s
    End Sub

    The above is my edited. the code above you gave gave an variable error "T". Moreover, the testdate that gave 12 as result, how would you like it to be accomplished? thru field in a form or do you have to input that in your code?

    because even you assign variable as date to call that function, you still have to quote that variable. I have tested my edited code and it worked.

    and I can't recall MONTH as access function but I think it is for Excel.

  3. #3
    Rameez is offline Advanced Beginner
    Windows XP Access 2003
    Join Date
    Jun 2009
    Location
    Chennai, India
    Posts
    40
    The thing works if i hardcode the date...the problem is that it will be in a function...with this function(testdate) called out...

    rs.movefirst
    do until rs.eof
    dim flag1 as boolean
    dim temp1 as string
    dim temp2 as string
    dim temp3 as string
    dim temp4 as date
    temp1=rs!field1
    temp2=rs!field2
    temp3=rs!field3
    temp4=rs!field4 'date field

    flag1= isdupeslam(temp1,temp2,temp3,temp4)
    ....
    ....

    rs.movenext
    loop

    if i hardcode temp4 as #1/1/2009# the code works...but not in the form of a variable being passed...

  4. #4
    marianne is offline Competent Performer
    Windows XP Access 2003
    Join Date
    Mar 2009
    Location
    Asia Pacific Region
    Posts
    150
    nope. on the contrary it worked on me. i have tested it. how did you coded that as a variable or on a form?

  5. #5
    Rameez is offline Advanced Beginner
    Windows XP Access 2003
    Join Date
    Jun 2009
    Location
    Chennai, India
    Posts
    40
    Quote Originally Posted by marianne View Post
    nope. on the contrary it worked on me. i have tested it. how did you coded that as a variable or on a form?

    oh...how did it work...

    I m just calling a sub updatedb()...inside the sub...i have a recordset rs defined on a query....for each row in that query...i m calling that
    isdupesla function...the main body is in my previous post.

  6. #6
    marianne is offline Competent Performer
    Windows XP Access 2003
    Join Date
    Mar 2009
    Location
    Asia Pacific Region
    Posts
    150
    we have new sub here uhm.... updatedb() ??? the code that worked for me on the other hand is what I've edited. maybe you have to revise your code.

  7. #7
    Rameez is offline Advanced Beginner
    Windows XP Access 2003
    Join Date
    Jun 2009
    Location
    Chennai, India
    Posts
    40
    For me the code you edited is giving 12 as the answer in message box...no matter what the date is...!!!!

  8. #8
    RuralGuy's Avatar
    RuralGuy is offline Administrator
    Windows 10 Access 2013 32bit
    Join Date
    Mar 2007
    Location
    8300' in the Colorado Rocky Mountains
    Posts
    12,922
    Have you tried this combination?

    Code:
    Function dater11(d1 As Date)
       Dim m1 As Integer
       Debug.Print d1
       m1 = Month("#" &  d1  & "#")...this code is to be corrected....
       Debug.Print m1
    End Function

  9. #9
    Rameez is offline Advanced Beginner
    Windows XP Access 2003
    Join Date
    Jun 2009
    Location
    Chennai, India
    Posts
    40
    yes i did try it...but to no avail...month function is not accepting the parameter given as a date...

    I had to deliver this code today...so what i did is instead of passing date...I have passed month and year as integers...

    it worked perfectly.
    here's the change i did...

    dim flag1 as boolean
    dim temp1 as string
    dim temp2 as string
    dim temp3 as string
    dim temp4 as integer
    dim temp5 as integer
    temp1=rs!field1
    temp2=rs!field2
    temp3=rs!field3
    temp4=DatePart("m",rs!field4)
    temp5=DatePart("yyyy",rs!field4)

    flag1= isdupeslam(temp1,temp2,temp3,temp4,temp5)
    ....
    ....

  10. #10
    RuralGuy's Avatar
    RuralGuy is offline Administrator
    Windows 10 Access 2013 32bit
    Join Date
    Mar 2007
    Location
    8300' in the Colorado Rocky Mountains
    Posts
    12,922
    Glad to hear you got it working.

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

Similar Threads

  1. problem in splitting Date and time fields
    By swaroop1012 in forum Queries
    Replies: 1
    Last Post: 11-22-2008, 11:29 AM
  2. Setting criteria in a calculated date field
    By SteveReberger in forum Access
    Replies: 0
    Last Post: 10-29-2008, 06:58 AM
  3. Extra date field update
    By georgft in forum Forms
    Replies: 0
    Last Post: 09-17-2008, 06:51 AM
  4. date/time field
    By James890 in forum Database Design
    Replies: 1
    Last Post: 04-18-2007, 07:51 AM
  5. Field Level Date validation
    By fadone in forum Forms
    Replies: 1
    Last Post: 12-09-2005, 10:23 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