Page 2 of 2 FirstFirst 12
Results 16 to 22 of 22
  1. #16
    redbull's Avatar
    redbull is offline Competent Performer
    Windows XP Access 2003
    Join Date
    Mar 2012
    Location
    Missouri
    Posts
    480

    Alright, I understand what your saying. Because it is reconnecting to the data every time.. move next will one move +1 from the first record.. has nothing to do with the last record at all. SO how would I fix something like this? and yea, I have to use an unbound form for this.

  2. #17
    RuralGuy's Avatar
    RuralGuy is offline Administrator
    Windows 7 64bit Access 2013
    Join Date
    Mar 2007
    Location
    8300' in the Colorado Rocky Mountains
    Posts
    12,917
    Because of this section of the code:
    Code:
    If Not r.EOF Then
      r.MoveNext
    End If

  3. #18
    redbull's Avatar
    redbull is offline Competent Performer
    Windows XP Access 2003
    Join Date
    Mar 2012
    Location
    Missouri
    Posts
    480
    I guess I am still not understanding...I tried this and received the same result..

    Code:
    Sub NextRecordbtn()
      Dim r As DAO.Recordset
    
    
    Set r = CurrentDb.OpenRecordset("MedplusCSV")  ' Query we want
    
    
    r.MoveNext
    
    
         'If Not r.EOF Then
         'r.MoveNext
         'End If
    
    
    If r.EOF Then
      r.MoveFirst
    End If
    
    
      Forms("frmmainnew").lbladdUser1bad.Visible = False
      Forms("frmmainnew").lbladdUser1bad.Visible = False
    
    
      Forms("frmmainnew").txtaddUser1.Value = r![f13] & " " & r![f14]
      Forms("frmmainnew").txtphone1.Value = r![F11]
      Forms("frmmainnew").txtRoles.Value = r![F15]
      Forms("frmmainnew").Text305.Value = r![F19]
      Forms("frmmainnew").Text308.Value = r![F16]
      Forms("frmmainnew").Text311.Value = r![F3]
      Forms("frmmainnew").Text299.Value = r![F41]
      Forms("frmmainnew").Text316.Value = r![F2]
    r.Close
    Set r = Nothing
    End Sub

  4. #19
    redbull's Avatar
    redbull is offline Competent Performer
    Windows XP Access 2003
    Join Date
    Mar 2012
    Location
    Missouri
    Posts
    480
    I think I found a solution... I added a loop that will make sure the current record is the same that the form displays.. after that is determined.. it will r.movenext... what do you think?

    Code:
    Sub NextRecordbtn()
      Dim r As DAO.Recordset
    
    
    Set r = CurrentDb.OpenRecordset("MedplusCSV")  ' Query we want
    
    
    Do Until Forms("frmmainnew").txtaddUser1.Value = r![f13] & " " & r![f14]
    r.MoveNext
    Loop
    
    
    If Not r.EOF Then
      r.MoveNext
    End If
    
    
    If r.EOF Then
      r.MoveFirst
    End If
    
    
      Forms("frmmainnew").lbladdUser1bad.Visible = False
      Forms("frmmainnew").lbladdUser1bad.Visible = False
    
    
      Forms("frmmainnew").txtaddUser1.Value = r![f13] & " " & r![f14]
      Forms("frmmainnew").txtphone1.Value = r![F11]
      Forms("frmmainnew").txtRoles.Value = r![F15]
      Forms("frmmainnew").Text305.Value = r![F19]
      Forms("frmmainnew").Text308.Value = r![F16]
      Forms("frmmainnew").Text311.Value = r![F3]
      Forms("frmmainnew").Text299.Value = r![F41]
      Forms("frmmainnew").Text316.Value = r![F2]
    r.Close
    Set r = Nothing
    End Sub

  5. #20
    RuralGuy's Avatar
    RuralGuy is offline Administrator
    Windows 7 64bit Access 2013
    Join Date
    Mar 2007
    Location
    8300' in the Colorado Rocky Mountains
    Posts
    12,917
    If it works the way you want then go with it.

  6. #21
    redbull's Avatar
    redbull is offline Competent Performer
    Windows XP Access 2003
    Join Date
    Mar 2012
    Location
    Missouri
    Posts
    480
    Alright, marking this headache as solved. Here is the final piece of the code.

    Code:
    Sub NextRecordbtn()
      Dim r As DAO.Recordset
    
    
    Set r = CurrentDb.OpenRecordset("Qry")  ' Query we want
    
    
    Do Until Forms("frmmainnew").txtaddUser1.Value = r![f13] & " " & r![f14]
    r.MoveNext
    Loop
    
    
    If r.EOF = False Then
      r.MoveNext
    End If
    
    
    If r.EOF = True Then
      r.MoveLast
    End If
    
    
      Forms("frmmainnew").lbladdUser1bad.Visible = False
      Forms("frmmainnew").lbladdUser1bad.Visible = False
    
    
      Forms("frmmainnew").txtaddUser1.Value = r![f13] & " " & r![f14]
      Forms("frmmainnew").txtphone1.Value = r![F11]
      Forms("frmmainnew").txtRoles.Value = r![F15]
      Forms("frmmainnew").Text305.Value = r![F19]
      Forms("frmmainnew").Text308.Value = r![F16]
      Forms("frmmainnew").Text311.Value = r![F3]
      Forms("frmmainnew").Text299.Value = r![F41]
      Forms("frmmainnew").Text316.Value = r![F2]
    r.Close
    Set r = Nothing
    End Sub

  7. #22
    rpeare is offline VIP
    Windows XP Access 2003
    Join Date
    Jul 2011
    Posts
    5,441
    what you're doing is opening the same recordset over and over again, reading the first record and populating the form with that record

    Let's say your query has the following records:

    Code:
    Query
    Record 1
    Record 2
    Record 3
    You are opening this query

    when you open your query it defaults to the first record (RECORD 1)
    If you're not at the EOF, you're reading a line (r.movenext)
    This takes you to RECORD 2
    If you're at the EOF you're going to the first record

    Then you're populating your form with the lookup values.

    The code as you have it will *ALWAYS* return the 2nd record in your recordset unless your recordset is 1 record.

    This is what I'm saying if you're determined to use your query as is it has to be sorted in the same order every time so you can figure out through your code where in your recordset you are

    Let's assume for the sage of argument that there is a PK inclucded in your query "Query" and all your data is sorted by that PK
    Further, let's assume that your form has a field called [PKField] which shows the pk (the field can have it's visible property set to false)


    Code:
    Set r = CurrentDb.OpenRecordset("Query")  
    ' Query we want 
    If isnull(PKField) then     
    'populates the data if there is no current record
        Forms("frmmainnew").lbladdUser1bad.Visible = False     
        Forms("frmmainnew").lbladdUser1bad.Visible = False     
        Forms("frmmainnew").txtaddUser1.Value = r![f13] & " " & r![f14]     
        Forms("frmmainnew").txtphone1.Value = r![F11]     
        Forms("frmmainnew").txtRoles.Value = r![F15]     
        Forms("frmmainnew").Text305.Value = r![F19]     
        Forms("frmmainnew").Text308.Value = r![F16]     
        Foms("frmmainnew").Text311.Value = r![F3]     
        Forms("frmmainnew").Text299.Value = r![F41]     
        Forms("frmmainnew").Text316.Value = r![F2]
    Else
        'cycle through all records in your recordset until the PK is greater than the current PK
        do while r.eof <> true
            if PKField <= r.fields("PK") then
                r.movenext         else
                'populates the data if there is no current record
                Forms("frmmainnew").lbladdUser1bad.Visible = False             
                Forms("frmmainnew").lbladdUser1bad.Visible = False             
                Forms("frmmainnew").txtaddUser1.Value = r![f13] & " " & r![f14]             
                Forms("frmmainnew").txtphone1.Value = r![F11]             
                Forms("frmmainnew").txtRoles.Value = r![F15]             
                Forms("frmmainnew").Text305.Value = r![F19]             
                Forms("frmmainnew").Text308.Value = r![F16]             
                Forms("frmmainnew").Text311.Value = r![F3]             
                Forms("frmmainnew").Text299.Value = r![F41]             
                Forms("frmmainnew").Text316.Value = r![F2]
                r.close
                exit sub
           End if
       loop 
    end if
    You'll have to modify it so that if you are at the last record it cycles to the first but that's fairly simple to do if you do a record count first, compare the record count to the current record count and if they're equal go back to the first record.

    I'd caution you that if you have a lot of records in your query "Query" this will be very inefficient because it will have to cycle through all records every time you want to switch records.

    You are far better of limiting your query to one record and finding a way to draw the critera from it from your form rather than cycle through data every time you want to next/prev.

Page 2 of 2 FirstFirst 12
Please reply to this thread with any new information or opinions.

Similar Threads

  1. Trouble selecting records from unbound box
    By premis in forum Access
    Replies: 6
    Last Post: 07-31-2012, 03:35 PM
  2. Unbound Form, but wish to save records...how?
    By LostInAccess in forum Forms
    Replies: 4
    Last Post: 07-18-2012, 09:55 AM
  3. Navigating from Form to SubForm
    By Gryphen957 in forum Forms
    Replies: 1
    Last Post: 11-19-2010, 10:08 AM
  4. No navigating through records??
    By cvansickle in forum Forms
    Replies: 2
    Last Post: 10-27-2010, 04:05 PM
  5. Help record navigating in forms
    By edo in forum Forms
    Replies: 0
    Last Post: 08-12-2008, 10:45 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