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

    Date Issues


    Hi Guy's this one is bugging me why records between 2 dates appear on a different date period but there are still only records added between dates on screen ????

    Please note, any names and vehicles are rubbed out on here, below is

    Code For initial adding

    Form Datasheet Criteria Code

    Form Datasheet results for 12/07/21 to 18/07/21

    Scroll back 2 weeks there results still appear scroll back to 28/06/21 to 04/07/21 ehhhh!!!!!

    Code on scroll back button "<"

    Initial Adding (taken From lstMS in Snip)

    Code:
    Dim rs As DAO.Recordset, rs2 As DAO.Recordset, rsEdit As DAO.Recordset, myDriver As String, myStart As Date, myEnd As Date, i As Integer, RecQty As Integer, optRecs As Integer, TotRecs As IntegerDim rsMS As DAO.Recordset, whDate As Date
    
    
    If IsNull(Me.cboDriver) Then
    MsgBox ("You Need To Select A Driver To Add Time Sheets"), vbInformation + vbOKOnly, "NO DRIVER SELECTED"
    DoCmd.CancelEvent
    Else
    
    
    myDriver = Me.cboDriver
    
    
    Me.lstDels.RowSource = "SELECT tblAssign.DeliveryDate, tblAssign.Vehicle, tblAssign.Driver, tblAssign.DelNo, tblAssign.DelTo, tblAssign.Town, tblAssign.PostCode From tblAssign GROUP BY tblAssign.DeliveryDate, tblAssign.Vehicle, tblAssign.Driver, tblAssign.DelNo, tblAssign.DelTo, tblAssign.Town, tblAssign.PostCode HAVING (((tblAssign.DeliveryDate) Between [Forms]![frmDriverHours]![txtStartDate] And [Forms]![frmDriverHours]![txtEndDate]) AND ((tblAssign.Driver)=[Forms]![frmDriverHours]![cboDriver])) ORDER BY tblAssign.DeliveryDate DESC , tblAssign.Driver;"
    Me.lstDels.Requery
    
    
    Forms!frmDriverHours.frmMileageSheetDS.Form.RecordSource = "SELECT tblJobSheets.DelDate, tblJobSheets.Vehicle, tblJobSheets.Driver, tblJobSheets.Del1, tblJobSheets.Del2, tblJobSheets.Del3, tblJobSheets.Del4, tblJobSheets.Del5, tblJobSheets.Del6, tblJobSheets.Del7, tblJobSheets.Del8, tblJobSheets.Del9, tblJobSheets.Del10, tblJobSheets.Del11, tblJobSheets.Del12, tblJobSheets.Del13, tblJobSheets.Del14, tblJobSheets.Del15 From tblJobSheets WHERE (((tblJobSheets.DelDate) Between [Forms]![frmDriverHours]![txtStartDate] And [Forms]![frmDriverHours]![txtEndDate]) AND ((tblJobSheets.Driver)=[Forms]![frmDriverHours]![cboDriver])) ORDER BY tblJobSheets.DelDate DESC;"
    Me.frmMileageSheetDS.Requery
    
    
    Me.lstMS.Requery
    
    
    myStart = Me.txtStartDate
    myEnd = Me.txtEndDate
    
    
    RecQty = Me.lstMS.ListCount
    If RecQty = 0 Then
    MsgBox ("There Are No Time Sheets To Add For:" & vbNewLine & vbNewLine & _
    Me.cboDriver & vbNewLine & vbNewLine & _
    "Between: " & Me.txtStartDate & vbNewLine & vbNewLine & _
    Me.txtEndDate & vbNewLine & vbNewLine & _
    "Perhaps " & Me.cboDriver & " Was Absent Within These Dates!"), vbInformation + vbOKOnly, "NO RECORDS TO ADD"
    DoCmd.CancelEvent
    Else
    If Not IsNull(DLookup("StartDate", "tblDriverHours", "[StartDate] Between #" & myStart & "# And #" & myEnd & "#")) Then
    DoCmd.CancelEvent
    Else
    Set rs = CurrentDb.OpenRecordset("Select * From tblDriverHours")
    With rs
    For i = 0 To Me.lstMS.ListCount - 1
    .AddNew
    !Driver = Me.cboDriver
    !StartDate = Format(Me.lstMS.Column(0, i), "dd-mmm-yyyy")
    !Rate = "9.00"
    !MSNo = Me.lstMS.Column(3, i)
    !StdHours = "37"
    .Update
    Next i
    End With
    End If
    Result

    Click image for larger version. 

Name:	Capture1.JPG 
Views:	29 
Size:	52.8 KB 
ID:	45767

    Datasheet Record Soucre

    Code:
    Forms!frmDriverHours!frmDriverHoursDS.Form.RecordSource = "SELECT tblDriverHours.Driver, tblDriverHours.StartDate, tblDriverHours.MSNo, " _& "tblDriverHours.StartTime, tblDriverHours.FinishTime, tblDriverHours.HoursDone, tblDriverHours.RestBreak, tblDriverHours.Rate, tblDriverHours.StdHours, " _
    & "tblDriverHours.HoursPaid, tblDriverHours.HoursOver, tblDriverHours.HoursBanked, tblDriverHours.Mins, tblDriverHours.HoursLeft, tblDriverHours.UnitHrs " _
    & "FROM tblDriverHours " _
    & "WHERE (((tblDriverHours.StartDate) Between [Forms]![frmDriverHours]![txtStartDate] And [Forms]![frmDriverHours]![txtEndDate])); "
    Me.frmDriverHoursDS.Requery
    Go Back 2 weeks and still there after the requery of Forms!DriverHoursDS ?

    Click image for larger version. 

Name:	Capture2.JPG 
Views:	28 
Size:	47.4 KB 
ID:	45769

    It's baffling me !!!!!

  2. #2
    Minty is offline VIP
    Windows 10 Office 365
    Join Date
    Sep 2017
    Location
    UK - Wiltshire
    Posts
    3,144
    Debug.print the recordsource of the sub form, after you think you have set it.
    By setting it you shouldn't need to requery it, it should just reload automatically?

    Personally, I would use Me.SubformControlName.Form.RecordSource to refer to the subform from the main form, just as I know it's the correct instance?

    EDIT: Actually if the form controls are your criteria in the sub form recordsource you don't need to do anything, a requery on it's own should do?
    DLookup Syntax and others http://access.mvps.org/access/general/gen0018.htm
    Please use the star below the post to say thanks if we have helped !
    ↓↓ It's down here ↓↓

  3. #3
    Gicu's Avatar
    Gicu is offline VIP
    Windows 10 Access 2010 32bit
    Join Date
    Jul 2015
    Location
    Kelowna, BC, Canada
    Posts
    4,235
    Hi Dave,
    Why would you set the record source of the subform in code and not simply use a saved query with your chosen criteria. Then you would need to simply do a requery (Me.frmDriverHoursDS.Form.Requery) in the AfterUpdate of the two date textboxes or where else you change them.
    Cheers,
    Vlad Cucinschi
    MS Access Developer
    http://forestbyte.com/

  4. #4
    DMT Dave is offline VIP
    Windows 10 Access 2016
    Join Date
    May 2018
    Posts
    1,329
    Hi Vlad, and Minty, yes i will adapt to your suggestion

    Kindest

  5. #5
    CJ_London is offline VIP
    Windows 10 Access 2010 32bit
    Join Date
    Mar 2015
    Posts
    11,845
    build your sql string like this, i.e. not including parameters in the query

    "WHERE (((tblDriverHours.StartDate) Between #" & [Forms]![frmDriverHours]![txtStartDate] & "# And #" & [Forms]![frmDriverHours]![txtEndDate] & "#")); "

    You really need to get into the habit of indenting code - extremely difficult to read otherwise.

    You also don't need to keep referencing tblDriverHours in your select part or need so many brackets in your where statement - but guess you have just copy/pasted this from a query

  6. #6
    Micron is offline Very Inert Person
    Windows 10 Access 2016
    Join Date
    Jun 2014
    Location
    Ontario, Canada
    Posts
    13,369
    You really need to get into the habit of indenting code - extremely difficult to read otherwise.
    I second that notion.
    @dmtdave; I cannot see how that can work - must be at least 2 End If's missing, which should be apparent if you indented. On that note, you might dissuade others from attempting to help if they cannot make sense of code that you post. I did not 'format' the long sql, which is also not very attractive to look at but I'd suggest you do that in your code, not just in a post.

    Code:
    If IsNull(Me.cboDriver) Then
       MsgBox ("You Need To Select A Driver To Add Time Sheets"), vbInformation + vbOKOnly, "NO DRIVER SELECTED"
       DoCmd.CancelEvent
    Else
       myDriver = Me.cboDriver
    
       Me.lstDels.RowSource = "SELECT tblAssign.DeliveryDate, tblAssign.Vehicle, tblAssign.Driver, tblAssign.DelNo,..."
       Me.lstDels.Requery
    
       Forms!frmDriverHours.frmMileageSheetDS.Form.RecordSource = "SELECT tblJobSheets.DelDate, tblJobSheets.Vehicle,..."
       Me.frmMileageSheetDS.Requery
       Me.lstMS.Requery
    
       myStart = Me.txtStartDate
       myEnd = Me.txtEndDate
    
       RecQty = Me.lstMS.ListCount
          If RecQty = 0 Then
             MsgBox ("There Are No Time Sheets To Add For:" & vbNewLine & vbNewLine & _
             Me.cboDriver & vbNewLine & vbNewLine & _
             "Between: " & Me.txtStartDate & vbNewLine & vbNewLine & _
             Me.txtEndDate & vbNewLine & vbNewLine & _
             "Perhaps " & Me.cboDriver & " Was Absent Within These Dates!"), vbInformation + vbOKOnly, "NO RECORDS TO ADD"
             DoCmd.CancelEvent
          Else
             If Not IsNull(DLookup("StartDate", "tblDriverHours", "[StartDate] Between #" & myStart & "# And #" & myEnd & "#")) Then
                DoCmd.CancelEvent
             Else
                Set rs = CurrentDb.OpenRecordset("Select * From tblDriverHours")
                With rs
                   For i = 0 To Me.lstMS.ListCount - 1
                      .AddNew
                      !Driver = Me.cboDriver
                      !StartDate = Format(Me.lstMS.Column(0, i), "dd-mmm-yyyy")
                      !Rate = "9.00"
                      !MSNo = Me.lstMS.Column(3, i)
                      !StdHours = "37"
                      .Update
                   Next i
                End With
             End If
          End If
    End If
    The more we hear silence, the more we begin to think about our value in this universe.
    Paraphrase of Professor Brian Cox.

  7. #7
    moke123's Avatar
    moke123 is offline Me.Dirty=True
    Windows 7 32bit Access 2010 32bit
    Join Date
    Oct 2012
    Location
    Ma.
    Posts
    1,859
    You really need to get into the habit of indenting code - extremely difficult to read otherwise.
    Dave,
    Here's a link to Smart Indenter, a free add on to indent code. It works on all versions of access.

    http://www.oaltd.co.uk/Indenter/Default.htm
    If this helped, please click the star * at the bottom left and add to my reputation- Thanks

  8. #8
    DMT Dave is offline VIP
    Windows 10 Access 2016
    Join Date
    May 2018
    Posts
    1,329
    Thank you guy's for your help, i have been dragged away from this and coming back to it soon as poss

    Will go though what you guy's have written, thank you

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

Similar Threads

  1. More date processing issues
    By WAVP375 in forum Access
    Replies: 9
    Last Post: 07-10-2018, 06:56 AM
  2. Date issues on equpment sent out
    By Shredder in forum Access
    Replies: 2
    Last Post: 05-23-2018, 03:15 PM
  3. VBA Sql date issues
    By Larryg in forum Queries
    Replies: 7
    Last Post: 04-02-2017, 02:29 PM
  4. Date format issues
    By budedwards in forum Queries
    Replies: 14
    Last Post: 03-15-2012, 10:52 AM
  5. Date expression issues
    By QTip in forum Queries
    Replies: 4
    Last Post: 01-06-2011, 03:43 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