Results 1 to 5 of 5
  1. #1
    Join Date
    Feb 2007
    Posts
    348

    Unanswered: Passed date through sub returns 12:00am

    This is probably a no brainer to you all but it confuses the daylights outta me:
    I wrote some code to go behind a form to generate a report. Basically, it gathers two dates and returns every record with an updated subrecord (took me all day to get that far). Then I wrote some error checking:

    Code:
    OldestTxt.SetFocus
    If OldestTxt.Text = Null Or OldestTxt.Text = "" Then
    MsgBox "oldest = null", vbCritical, "oldest"
     OldestDay = 1 / 1 / 1901
    Else
    MsgBox "oldest =" & OldestTxt.Value, vbCritical, "oldest"
     OldestDay = OldestTxt
    End If
    After I got that working, I realized I could reuse this in a couple places, all on this form so far so I wrote:

    Code:
    Public Sub VerifyOldest(oldest As Date)
    
    OldestTxt.SetFocus
    If OldestTxt.Text = Null Or OldestTxt.Text = "" Then
     oldest = 1 / 1 / 1901
    Else
     oldest = OldestTxt
    End If
    
    End Sub
    and called it with:
    Code:
    VerifyOldest (OldestDay)
    Now I've never written a parametered sub before so it's quite possible there is something obviously wrong with all that.

    The weird thing is though, that before the sub (and when I uncomment the code I was trying to move into the sub it did what I wanted, defaulted in 01/01/1901 which is used to filter the report I want. When I move it to the sub, it seems to return 12:00 AM no matter what I enter.

    What am I doing that is wrong?
    thanks.

  2. #2
    Join Date
    May 2007
    Posts
    38
    any time record is really a date and time

    youre date is a date with no time, so i presume no time (or zero) is 12am.

    you have probably formatted your field as short time or medium time

    it needs to be short DATE then it will be ok

    good luck

  3. #3
    Join Date
    Feb 2007
    Posts
    348
    hmm, sounds very reasonable. I'll have to take a look next week. I thought I had set it to Date but I wonder if I had a typo or something, spawning a new variable that is not set correctly, thus your idea.

    thanks

  4. #4
    Join Date
    Dec 2004
    Location
    Madison, WI
    Posts
    3,926
    Doesn't this:
    oldest = 1 / 1 / 1901
    need to be this:
    oldest = #1/1/1901#
    ??

    And if you pass a date to the sub/function don't you also need to use the # around the value for the value being passed (or as suggested format it as a date) - ie. myVariable = format(myfield,"mm/dd/yyyy")?
    Last edited by pkstormy; 05-26-07 at 14:31.
    Expert Database Programming
    MSAccess since 1.0, SQL Server since 6.5, Visual Basic (5.0, 6.0)

  5. #5
    Join Date
    Feb 2007
    Posts
    348
    ah, that could be it. Those pound signs stumped me for a major portion of the day on Friday. I'll spend some time with it today.
    Thanks very much.

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts
  •