Results 1 to 11 of 11
  1. #1
    DMT Dave is offline VIP
    Windows 10 Access 2016
    Join Date
    May 2018
    Posts
    1,371

    Date Won't Add To Table!!!

    Hi Guy's, good day to you all, for some reason that i can't figure out why a date won't add to a date field!!!

    Hope you can see something i can't see

    XL Sheet Cell Value Is: Tue 08/04/2025

    (Set The Recordset)
    Set rs = CurrentDb.OpenRecordset("SELECT * FROM tblEdit WHERE 1 = 0") 'you don't use these values so load an empty recordset on the table



    (Now remove Tue from XL cell)
    strDate = CDate(Right(xlSHT.Cells(i, 11).Value, Len(xlSHT.Cells(i, 11).Value) - InStr(xlSHT.Cells(i, 11).Value, " "))) ' Ready Date

    (Get Friday Prior Date)
    dtShipDate = DateAdd("d", -1 - Weekday(strDate), strDate) ' Add To Fridays Date Prior To strDate (Ready Date)

    (Set Main Form Date)
    Forms!frmMainMenu!frmIndex1!cboShipmentDateIndex1 = dtShipDate ' Adding dtShipDate Fine

    Debug.Print "Date On XL Sheet: " & strDate; vbCrLf & _
    "Ship Date: " & dtShipDate

    Immediate Window
    Date On XL Sheet: 08/04/2025
    Ship Date: 04/04/2025

    Now Add To ShipmentDate Field

    With rs
    .AddNew
    !ShipmentDate = dtShipDate

    dtShipDate Not Adding To ShipmentDate Field ???

    spent a while stepping through this, it should be simple

    Sorry not added code tags, but didn't because of short snips

    If i need to add more, can add more and would put into code tags

    thank you guys

  2. #2
    Join Date
    Jan 2017
    Location
    Swansea,South Wales,UK
    Posts
    6,574
    You really should not have the day in the cell, just the date. You can format the cell so you want to see the day in there as well.
    If you do that then you will have a date, which you should know by now is just a number.

    I used to use that 1=0 option to get an empty recordset, but there is an option on the OpenRecordset to do that, but can I find it now? The hell I can.
    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

  3. #3
    CJ_London is offline VIP
    Windows 10 Access 2010 32bit
    Join Date
    Mar 2015
    Posts
    11,941
    If you are showing all your code then you are missing some
    https://learn.microsoft.com/en-us/of...-dao-recordset

  4. #4
    DMT Dave is offline VIP
    Windows 10 Access 2016
    Join Date
    May 2018
    Posts
    1,371
    Hi CJ, WGM, sorry i only added the part upto failure, i am adding many extra field data then at the end, its important for me to say

    .update
    .close
    set rs = Nothing

    I don't believe i need

    rs!Fields("ShipmentDate") = dtShipDate

    instead of !ShipmentDate = dtShipDate

    because it's within a With Block ?

  5. #5
    DMT Dave is offline VIP
    Windows 10 Access 2016
    Join Date
    May 2018
    Posts
    1,371
    I could cheat and add an insert sql at the end where ShipmentDate is null but that doesn't tell me why initially it's not populating the date field

  6. #6
    Join Date
    Jan 2017
    Location
    Swansea,South Wales,UK
    Posts
    6,574
    Upload a db with enough to see the issue.
    Do you have an End With statement?
    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

  7. #7
    DMT Dave is offline VIP
    Windows 10 Access 2016
    Join Date
    May 2018
    Posts
    1,371
    WGM, CJ, please forgive me with all of your mite,

    this won't help, what an idiot

    Add it then wipe it why not!!!!!!!!!!

    Code:
    With rs       
     For iQty = 1 To x
            .AddNew
                !ShipmentDate = dtShipDate
                !Year = Format(dtShipDate, "yyyy")
                !Quarter = Format(dtShipDate, "q")
                !Month = Format(dtShipDate, "m")
                !Week = Format(dtShipDate, "ww")
                !Customer = sCust
                !CustAdd1 = sCustAdd1
                !CustAdd2 = sCustAdd2
                !CustTown = sCustTown
                !CustPostCode = sCustPC
                !ShipmentDate = Null

  8. #8
    Join Date
    Jan 2017
    Location
    Swansea,South Wales,UK
    Posts
    6,574

    Show ALL of your code from now on please
    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
    DMT Dave is offline VIP
    Windows 10 Access 2016
    Join Date
    May 2018
    Posts
    1,371
    certainly WGM, just didn't want to spend a while removing sensitive data when i just knew 100% it was a contradiction in the code, but i know you guy's can only see/fix whats in front of you

  10. #10
    Join Date
    Jan 2017
    Location
    Swansea,South Wales,UK
    Posts
    6,574
    Use this for anything sensitive.
    Randomize Data
    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

  11. #11
    DMT Dave is offline VIP
    Windows 10 Access 2016
    Join Date
    May 2018
    Posts
    1,371
    Will check that out WGM, i didn't mean that i didn't want to spend a while removing sensitive data, it was more that i didn't have time on my hands while at work to do so.

    We as people who ask for advice have to understand you guy's can only scan / fix / repair / advise / what you can see on screen

    you all put great effort in to help people, but you need help to be able to help....

    I think its hard for you guy's as you have to understand:

    What the main goal is
    different prefixes being used in variables
    sequence of events

    well done you all for help you give everyone

    will check that randomiser out (prob at home when more time)

    Kindest and fab day

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

Similar Threads

  1. Replies: 2
    Last Post: 04-19-2019, 05:13 PM
  2. Replies: 29
    Last Post: 03-11-2016, 08:44 PM
  3. "Add user" subform won't show up!
    By apc0243 in forum Access
    Replies: 2
    Last Post: 01-26-2015, 02:29 PM
  4. Replies: 1
    Last Post: 11-16-2014, 09:10 AM
  5. Between [start date] and [end date] won't work
    By BCJourney in forum Queries
    Replies: 7
    Last Post: 01-17-2013, 10:01 AM

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