Results 1 to 15 of 15
  1. #1
    GraeagleBill's Avatar
    GraeagleBill is offline Experienced Old Geezer
    Windows 10 Access 2013 32bit
    Join Date
    Feb 2011
    Posts
    1,919

    Format(Date,"mm/dd/yyyy") = 12/30/1899

    Format(Date,"mm/dd/yyyy") = 12/30/1899
    Silly me, I was expecting 03/28/2022

    Same thing if I
    Dim dteDate as date
    dteDate =Date()


    msgbox format(dtedate, "mm/dd/yyyy")
    12/30/1899

    It's been a long day, but this one's "off the charts.

    Maybe the clue is here:
    Code:
    strSql = "INSERT INTO Groupings(RegistryID,GroupID,GroupPhoneBroadcast,DateAdded)"
    strSql = strSql & " VALUES(" & numRegID & ", " & numGrpID & ", " & bolAutoBroadcast & ", " & Format(Date, "mm/dd/yyyy") & ");"
    "DateAdded" field in table Groupings is Date/Time. It's format is mm/dd/yyyy

    Click image for larger version. 

Name:	000.jpg 
Views:	24 
Size:	59.9 KB 
ID:	47576

  2. #2
    June7's Avatar
    June7 is offline VIP
    Windows 10 Access 2010 32bit
    Join Date
    May 2011
    Location
    The Great Land
    Posts
    52,963
    Well, I don't know why your VBA is wrong but the SQL statement needs # delimiters for the date input.
    How to attach file: http://www.accessforums.net/showthread.php?t=70301 To provide db: copy, remove confidential data, run compact & repair, zip w/Windows Compression.

  3. #3
    GraeagleBill's Avatar
    GraeagleBill is offline Experienced Old Geezer
    Windows 10 Access 2013 32bit
    Join Date
    Feb 2011
    Posts
    1,919
    Thanks, that did the trick.......... I should have known that one (I couldn't re-produce the 1899, so have no idea how I managed that one?)
    Code:
    strSql = "INSERT INTO Groupings(RegistryID,GroupID,GroupPhoneBroadcast,DateAdded)"
    strSql = strSql & " VALUES(" & numRegID & ", " & numGrpID & ", " & bolAutoBroadcast & ", #" & Format(Date, "mm/dd/yyyy") & "#);"

  4. #4
    June7's Avatar
    June7 is offline VIP
    Windows 10 Access 2010 32bit
    Join Date
    May 2011
    Location
    The Great Land
    Posts
    52,963
    On reflection, why do you even use Format function? Consider:

    & bolAutoBroadcast & ", Date());"
    How to attach file: http://www.accessforums.net/showthread.php?t=70301 To provide db: copy, remove confidential data, run compact & repair, zip w/Windows Compression.

  5. #5
    isladogs's Avatar
    isladogs is offline MVP / VIP
    Windows 10 Office 365
    Join Date
    Jan 2014
    Location
    Somerset, UK
    Posts
    5,992
    In Access, days are counted from a baseline date of 12/30/1899. So that output indicates that the expression had no data. Null isn't allowed for numbers so was resolved as value zero
    Colin, Access MVP, Website, email
    The more I learn, the more I know I don't know. When I don't know, I keep quiet!
    If I don't know that I don't know, I don't know whether to answer

  6. #6
    GraeagleBill's Avatar
    GraeagleBill is offline Experienced Old Geezer
    Windows 10 Access 2013 32bit
    Join Date
    Feb 2011
    Posts
    1,919
    Ah! I've always thought the epoch was 01/01/1900, so it didn't occur to me what 12/30/1899 might be.

  7. #7
    GraeagleBill's Avatar
    GraeagleBill is offline Experienced Old Geezer
    Windows 10 Access 2013 32bit
    Join Date
    Feb 2011
    Posts
    1,919
    That's how I started, but the default date format excludes leading zeros. The only way I could get the table to update with leading zeros was to stipulate the format mm/dd/yyyy in the field definition in the table design itself. But yes, having done that, your suggestion works fine.

  8. #8
    Join Date
    Jan 2017
    Location
    Swansea,South Wales,UK
    Posts
    5,008
    No one mentioned reserved word?
    Please use # icon on toolbar when posting code snippets.
    Cross Posting: https://www.excelguru.ca/content.php?184
    Debugging Access: https://www.youtube.com/results?sear...bug+access+vba

  9. #9
    isladogs's Avatar
    isladogs is offline MVP / VIP
    Windows 10 Office 365
    Join Date
    Jan 2014
    Location
    Somerset, UK
    Posts
    5,992
    Where has a reserved word been used? Its the Date function not a field called Date.
    Colin, Access MVP, Website, email
    The more I learn, the more I know I don't know. When I don't know, I keep quiet!
    If I don't know that I don't know, I don't know whether to answer

  10. #10
    June7's Avatar
    June7 is offline VIP
    Windows 10 Access 2010 32bit
    Join Date
    May 2011
    Location
    The Great Land
    Posts
    52,963
    Using Format function or format property in table has nothing to do with how value is stored in Date/Time field. If you want date displayed with placeholder zeroes, set format in textbox. Advise not to do any data formatting in table.
    How to attach file: http://www.accessforums.net/showthread.php?t=70301 To provide db: copy, remove confidential data, run compact & repair, zip w/Windows Compression.

  11. #11
    GraeagleBill's Avatar
    GraeagleBill is offline Experienced Old Geezer
    Windows 10 Access 2013 32bit
    Join Date
    Feb 2011
    Posts
    1,919
    I will heed your caution, but why would that cause any problems?

  12. #12
    Join Date
    Jan 2017
    Location
    Swansea,South Wales,UK
    Posts
    5,008
    Quote Originally Posted by isladogs View Post
    Where has a reserved word been used? Its the Date function not a field called Date.
    How can the real Date variable not have a value?
    Please use # icon on toolbar when posting code snippets.
    Cross Posting: https://www.excelguru.ca/content.php?184
    Debugging Access: https://www.youtube.com/results?sear...bug+access+vba

  13. #13
    isladogs's Avatar
    isladogs is offline MVP / VIP
    Windows 10 Office 365
    Join Date
    Jan 2014
    Location
    Somerset, UK
    Posts
    5,992
    Quote Originally Posted by Welshgasman View Post
    How can the real Date variable not have a value?
    No idea. Bill said it wasn't reproducible
    Colin, Access MVP, Website, email
    The more I learn, the more I know I don't know. When I don't know, I keep quiet!
    If I don't know that I don't know, I don't know whether to answer

  14. #14
    June7's Avatar
    June7 is offline VIP
    Windows 10 Access 2010 32bit
    Join Date
    May 2011
    Location
    The Great Land
    Posts
    52,963
    Setting formatting can obscure what is actually stored in field. A poster provided a database that formatted a date/time field to MMM-yyyy, couldn't see the day. Found it annoying and had to remove. If a date/time field has data with time components, setting format to MM/DD/YYYY can cause frustration when filtering doesn't perform as expected and the cause is not obvious because time components are not displayed.
    How to attach file: http://www.accessforums.net/showthread.php?t=70301 To provide db: copy, remove confidential data, run compact & repair, zip w/Windows Compression.

  15. #15
    GraeagleBill's Avatar
    GraeagleBill is offline Experienced Old Geezer
    Windows 10 Access 2013 32bit
    Join Date
    Feb 2011
    Posts
    1,919
    Ah yes! I see what you mean. Not many of my apps have time displays, but I can see from your point where I could find more trouble than I'd like.
    Thanks,
    Bill

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

Similar Threads

  1. Replies: 1
    Last Post: 12-07-2021, 12:45 PM
  2. Replies: 10
    Last Post: 08-08-2019, 11:05 AM
  3. Replies: 2
    Last Post: 06-25-2014, 11:00 AM
  4. Replies: 15
    Last Post: 05-27-2014, 10:00 PM
  5. UK Date Format In Linked Table ("dd/mm/yyyy")
    By smoothlarryhughes in forum Queries
    Replies: 1
    Last Post: 06-18-2013, 08: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