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

    Moving To Next List Row

    Hi Guy's is there an adjustment that can be made here ?



    RecQty (this is list count) with no Headers so Row 0 is a record

    If for example there are 3 rows, i want to be able to move down the list for the next record until the last count

    in my code !StartDate = Format(Me.lstMS.Column(0, 0), "ddd-dd-mmm-yyyy")

    If listcount is 3
    !StartDate = Format(Me.lstMS.Column(0, 0), "ddd-dd-mmm-yyyy")
    !StartDate = Format(Me.lstMS.Column(0, 1), "ddd-dd-mmm-yyyy")
    !StartDate = Format(Me.lstMS.Column(0, 2), "ddd-dd-mmm-yyyy")

    !MSNo = Me.lstMS.Column(3, 0)
    !MSNo = Me.lstMS.Column(3, 1)
    !MSNo = Me.lstMS.Column(3, 2)

    Code:
    Set rs = CurrentDb.OpenRecordset("Select * From tblDriverHours")With rs
    For i = 1 To RecQty
    .AddNew
    !Driver = Me.cboDriver
    !StartDate = Format(Me.lstMS.Column(0, 0), "ddd-dd-mmm-yyyy")
    !MSNo = Me.lstMS.Column(3, 0)
    .Update
    Next i
    End With
    Hope this makes sense !!!

  2. #2
    Join Date
    Jan 2017
    Location
    Swansea,South Wales,UK
    Posts
    6,570
    You are not using i though?
    I also would not store a formatted date?, that makes it a string? Just format it as required when needed.?
    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
    Micron is online now Very Inert Person
    Windows 10 Access 2016
    Join Date
    Jun 2014
    Location
    Ontario, Canada
    Posts
    13,425
    I agree with don't store a formatted date. If that becomes the decision I suppose a fix is no longer needed.

    Code:
    For i = 1 To RecQty
    I don't see where you figure out RecQty - it's likely 1 or zero in that code so no loop anyway. I suggest ALWAYS verify your variable values to trouble shoot. Anyway, I'm not sure I understand the goal but for future consideration maybe want you'd want is
    (Me.lstMS.Column(0, Me.ListCount), "ddd-dd-mmm-yyyy")

    This sort of thing is subject to being screwed up by future design changes, so another reason maybe why to not do it. If you later decide to see the list headers and forget about this code, you end up with unexpected results.
    The more we hear silence, the more we begin to think about our value in this universe.
    Paraphrase of Professor Brian Cox.

  4. #4
    moke123's Avatar
    moke123 is offline Me.Dirty=True
    Windows 7 32bit Access 2010 32bit
    Join Date
    Oct 2012
    Location
    Ma.
    Posts
    1,880
    If you trying to iterate through a listbox you need something like:

    Code:
        Dim i As Integer
    
    
        For i = 0 To Me.lstMS.ListCount - 1
    
    
            !StartDate = Me.lstMS.Column(0, i)
    
    
            !MSNo = Me.lstMS.Column(3, i)
    
    
        Next i
    If this helped, please click the star * at the bottom left and add to my reputation- Thanks

  5. #5
    DMT Dave is offline VIP
    Windows 10 Access 2016
    Join Date
    May 2018
    Posts
    1,371
    Hi Moke, thank you works superb

  6. #6
    Micron is online now Very Inert Person
    Windows 10 Access 2016
    Join Date
    Jun 2014
    Location
    Ontario, Canada
    Posts
    13,425
    Doesn't that simply make MSNo = first list item 1 column value then list item 2 column value then list item 3 column value ... then list item n column value? Why not just use the nth list item column value?
    Last edited by Micron; 07-05-2021 at 11:41 AM. Reason: clarification
    The more we hear silence, the more we begin to think about our value in this universe.
    Paraphrase of Professor Brian Cox.

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

Similar Threads

  1. Replies: 8
    Last Post: 12-13-2017, 10:38 AM
  2. Replies: 1
    Last Post: 12-09-2016, 08:58 AM
  3. Replies: 4
    Last Post: 11-10-2013, 09:16 AM
  4. Moving from vs 07 to vs 97
    By Kilroy2.0 in forum Access
    Replies: 4
    Last Post: 06-04-2010, 08:42 AM
  5. Help with Moving names
    By Mcinsane in forum Access
    Replies: 1
    Last Post: 06-04-2009, 01:04 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