Results 1 to 3 of 3
  1. #1
    Salty Mariner is online now Intermediate
    Windows 11 Access 2021
    Join Date
    Dec 2023
    Location
    Corpus Christi, TX
    Posts
    83

    Assistance with a Function

    I have a Function (actually two similar ones) that are not giving me the desired results.



    Here is the code:

    Code:
    Private Function GetNextLat()
    Dim strNextLat As String
    Dim rst As DAO.Recordset
    
    
        Set rst = Me.RecordsetClone
        
        With rst
            If Not .EOF Then
                .FindFirst ("LegNo = " & Nz(Me.LegNo, 0) + 1)
                strNextLat = rst![Latitude]
            End If
        End With
        
        GetNextLat = strNextLat
        
        rst.Close
        Set rst = Nothing
    End Function
    It's purpose is to look ahead on a continuous form and grab the contents of the next record...In this case a Latitude.(I have another for Longitude) Everything works great until I get to the last record. Even though I have checked for EOF to exclude the last record It seems to be returning a zero and then adding 1 which takes me full circle to record 1. I can see where my logic is breaking but I'm striking out trying to fix this. I thought that by checking for EOF It would stop and I could deal with it and return an empty string.

    Suggestions?

  2. #2
    June7's Avatar
    June7 is offline VIP
    Windows 10 Access 2010 32bit
    Join Date
    May 2011
    Location
    The Great Land
    Posts
    52,952
    The last record is not EOF. So, code attempts to pull from next record which does not exist. Not sure Nz() is needed.

    .FindFirst ("LegNo = " & Me.LegNo + 1)

    If that doesn't work, try:

    .FindFirst ("LegNo = " & Nz(Me.LegNo, -1) + 1)

    Should probably use NoMatch property after FindFirst

    If Not .NoMatch Then strNextLat = ![Latitude]

    Could use DLookup() in textbox.

    =DLookup("Latitude", "tablename", "LegNo=" & [LegNo] + 1)
    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
    Salty Mariner is online now Intermediate
    Windows 11 Access 2021
    Join Date
    Dec 2023
    Location
    Corpus Christi, TX
    Posts
    83
    This

    .FindFirst ("LegNo = " & Me.LegNo + 1)

    and

    If Not .NoMatch Then strNextLat = ![Latitude]

    worked like a charm!

    Thank you so much June.

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

Similar Threads

  1. Need assistance
    By Dave14867 in forum Access
    Replies: 2
    Last Post: 12-18-2018, 10:54 AM
  2. need some assistance
    By WillemTWC in forum Access
    Replies: 20
    Last Post: 03-14-2018, 12:10 AM
  3. Assistance with the InStr function
    By aellistechsupport in forum Queries
    Replies: 3
    Last Post: 09-13-2017, 08:18 PM
  4. VBA assistance
    By Kwbrown in forum Programming
    Replies: 3
    Last Post: 03-15-2014, 03:09 PM
  5. Qry Assistance Please
    By buck in forum Access
    Replies: 8
    Last Post: 12-31-2013, 08:52 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