Results 1 to 12 of 12
  1. #1
    Join Date
    Aug 2004
    Location
    NY
    Posts
    113

    Unanswered: VBA Date is Null

    I am getting a Null error on the following:
    Code:
    Dim CompDate As String
    CompDate = Date
        
    Me.txtDate.Value = CompDate
        Me.txtDate.Locked = True
    Any ideas why? The event is trigged by selecting a dropdown combo.

    Thanks
    ======================
    Levent
    Access 3

  2. #2
    Join Date
    May 2008
    Location
    Raleigh, NC
    Posts
    151

    On GotFocus()

    I put your code in the control's GotFocus event and it worked fine for me. I made sure that control did not immediately get focus when the form opened as well.

    Sorry if this isn't much help.
    Stu

  3. #3
    Join Date
    May 2005
    Location
    Nevada, USA
    Posts
    2,888
    Provided Answers: 6
    You don't have a data field or control named "Date", do you? You can explicitly force it to use the function with:

    VBA.Date
    Paul

  4. #4
    Join Date
    Mar 2003
    Location
    The Bottom of The Barrel
    Posts
    6,102
    Provided Answers: 1
    Check your references for a missing visual basic library.
    oh yeah... documentation... I have heard of that.

    *** What Do You Want In The MS Access Forum? ***

  5. #5
    Join Date
    Jun 2005
    Location
    Richmond, Virginia USA
    Posts
    2,763
    Provided Answers: 19
    You have to understand that Access' error messages are notorious for not really reflecting the actual error. The mistake in the code

    Code:
    Dim CompDate As String
    CompDate = Date
    that I see, is that you're declaring CompDate as a String, then assigning Date to it! Try

    Code:
    Dim CompDate As Date
    CompDate = Date
    and see what happens.
    Hope this helps!

    The problem with making anything foolproof...is that fools are so darn ingenious!

    All posts/responses based on Access 2003/2007

  6. #6
    Join Date
    May 2005
    Location
    Nevada, USA
    Posts
    2,888
    Provided Answers: 6
    That will not cause an error Linq (a previous poster already noted the code worked fine for them, and to be sure I just tested as well).
    Paul

  7. #7
    Join Date
    Nov 2007
    Location
    Adelaide, South Australia
    Posts
    4,049
    Have you tried setting a breakpoint and then running the code to see where the Null is coming from?

    You could also try just using Me.txtDate = Date() instead of all that code, just for fun
    Owner and Manager of
    CypherBYTE, Microsoft Access Development Specialists.
    Microsoft Access MCP.
    And all around nice guy!


    "Heck it's something understood by accountants ... so it can't be 'that' difficult..." -- Healdem
    "...teach a man to code and he'll be frustrated for life! " -- georgev

  8. #8
    Join Date
    Nov 2004
    Location
    out on a limb
    Posts
    13,692
    Provided Answers: 59
    erm... can we just check that you are trying to use the dat function, and that you don't have a control (in the form or report), a varaible (in a bit of VBA) OR column in the table called DATE... if so then thats NOT a good idea, especially the column in a table one can cause all sorts of problmes when you sue a reserved word.

    if the value is coming from a source other than the DATE function then you may need to test the value to see if its valid before assigning it using the NZ or IS NULL functions and handle the condition appropriately
    I'd rather be riding on the Tiger 800 or the Norton

  9. #9
    Join Date
    Jan 2007
    Location
    UK
    Posts
    11,434
    Provided Answers: 10
    I can't believe how long it took for someone to notice the fact he was sticking a date in a STRING variable?! Ugh, nasty!

    Use date variables to store dates and most of your probelms will go away - even if it doesn't solve this specific one it's certainly not helping you!
    George
    Home | Blog

  10. #10
    Join Date
    Mar 2003
    Location
    The Bottom of The Barrel
    Posts
    6,102
    Provided Answers: 1
    If you want to get into best practices, the correct question is why is he using an intermediate variable at all. Baby steps...
    oh yeah... documentation... I have heard of that.

    *** What Do You Want In The MS Access Forum? ***

  11. #11
    Join Date
    Nov 2007
    Location
    Adelaide, South Australia
    Posts
    4,049
    That was my point too... cryptic as it was.
    Owner and Manager of
    CypherBYTE, Microsoft Access Development Specialists.
    Microsoft Access MCP.
    And all around nice guy!


    "Heck it's something understood by accountants ... so it can't be 'that' difficult..." -- Healdem
    "...teach a man to code and he'll be frustrated for life! " -- georgev

  12. #12
    Join Date
    Jul 2003
    Location
    Michigan
    Posts
    1,941
    Quote Originally Posted by Teddy
    If you want to get into best practices, the correct question is why is he using an intermediate variable at all. Baby steps...
    Unless the poster really meant:

    Code:
    Dim CompDate As String
    CompDate = Date
    ...
    'perform various string manipulations to CompDate    
    ...
    Me.txtDate.Value = CompDate
        Me.txtDate.Locked = True
    Inspiration Through Fermentation

Posting Permissions

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