Problem with DateAdd and Default Value

Collapse
X
 
  • Time
  • Show
Clear All
new posts
  • missinglinq
    Recognized Expert Specialist
    • Nov 2006
    • 3533

    Problem with DateAdd and Default Value

    Here's a poser! Using Access 2003 SP2

    The Control Source for txtMealDate is defined at table level as Date/Time.

    When this code is run
    Code:
    Private Sub txtMealDate_AfterUpdate()
     txtMealDate.DefaultValue = DateAdd("d", 1, Me.txtMealDate)
     MsgBox txtMealDate.DefaultValue
    End Sub
    the messagebox pops up with the correct DefaultValue. But when I move to a new record, the date entered as default is 12/30/1899. I've deleted the form and re-created it , as well as the table. I've been taking cold medicines that have me kind of spacey, so I figure it's got to be something simple I'm overlooking. I'd appreciate any ideas, as my hair is already sparse and I'm pulling out more by the minute!

    Linq ;0)>
  • FishVal
    Recognized Expert Specialist
    • Jun 2007
    • 2656

    #2
    Hello, Linq.

    TextBox.Default Value property is of String type and date delimiters (#) should be added to a string value assigned to it.

    Regards,
    Fish.

    P.S. Where did you get such a powerful medcine? ;)

    Comment

    • missinglinq
      Recognized Expert Specialist
      • Nov 2006
      • 3533

      #3
      Over the county!

      Tried that! Tried wrapping it in CDate() as well.

      Linq ;0)>

      Comment

      • FishVal
        Recognized Expert Specialist
        • Jun 2007
        • 2656

        #4
        Originally posted by missinglinq
        Over the county!

        Tried that! Tried wrapping it in CDate() as well.

        Linq ;0)>
        :)

        I guess that means doesn't work.
        But it does.

        TextBox.Default Value is String type property.
        (BTW, though I didn't check it personally, but it most like that date should be formatted like when displayed in that particular Textbox control)
        Being such it gets and returns String type values.
        Date delimiters, "#", has to be included in the string value assigned to the property.

        txb.DefaultValu e = "#" & dteVariable & "#"

        P.S. What is an API (Active Pharmaceutical Ingridient LOL) of the medcine you've taken? :D

        Comment

        • missinglinq
          Recognized Expert Specialist
          • Nov 2006
          • 3533

          #5
          As I said, I tried wrapping it in the # delimiter, like you would if you were doing a hack tp simply carry a value forward, but couldn't get it to work. Like a dummy (or maybe a 'doped') I neglected to wrap the pound mark in quotes! This does it:

          Code:
          Private Sub txtMealDate_BeforeUpdate(Cancel As Integer)
           txtMealDate.DefaultValue = "#" & DateAdd("d", 1, Me.txtMealDate) & "#"
          End Sub
          Thanks for your help, Fish!

          Linq ;0)>

          BTW, the magic elixir is CODEINE!

          Comment

          • FishVal
            Recognized Expert Specialist
            • Jun 2007
            • 2656

            #6
            Originally posted by missinglinq
            Thanks for your help, Fish!

            Linq ;0)>
            You are most welcome. :)

            BTW, the magic elixir is CODEINE!
            I would prefer Jagermeister - a magic of the Light Side. :D

            Comment

            • missinglinq
              Recognized Expert Specialist
              • Nov 2006
              • 3533

              #7
              Egads! Took Jagermeister on a camping trip once, my camping mates said I was actually howling at the moon before the the night was thru!

              Linq ;0)>

              Comment

              • NeoPa
                Recognized Expert Moderator MVP
                • Oct 2006
                • 32645

                #8
                Hi guys.

                Late to the party it seems, but I'm glad to see that Fish has helped you to resolve the issue Linq :)

                12/30/1899 (or 30/12/1899 for Euros) is actually the date representation of 0 (not -1 as I'd anticipated. Why it starts before the beginning of the new century is a mystery to me).

                I'm surprised a simple CDate() return value wouldn't work mind you.

                Comment

                • missinglinq
                  Recognized Expert Specialist
                  • Nov 2006
                  • 3533

                  #9
                  I was too, Ade, but as John Walton used to say "Life's a mystery!"

                  ;0)>

                  Comment

                  Working...