Results 1 to 4 of 4
  1. #1
    lawdy is offline Competent Performer
    Windows XP Access 2010 32bit
    Join Date
    Jan 2013
    Posts
    172

    How to move to next record in a select query

    I have to following code on a button:

    pubLngProposalNo = [tbLngProposalNo] ' get the current proposal number
    Dim d As DAO.Database
    Dim r As DAO.Recordset
    Dim strSQL As String
    strSQL = "SELECT tblProposal.fLngProposalNo, tblProposal.fTxtCompany " _
    & "From tblProposal " _


    & "WHERE (((tblProposal.fLngProposalNo)>= " & pubLngProposalNo & "));"
    Set r = CurrentDb.OpenRecordset(strSQL)
    Debug.Print "fTxtCompany " & fTxtCompany

    I can only reference the first record in the query results. How do I reference the other records in the query. I push a button on the form which it should get several proposal numbers and company names?

  2. #2
    ssanfu is offline Master of Nothing
    Windows XP Access 2000
    Join Date
    Sep 2010
    Location
    Anchorage, Alaska, USA
    Posts
    9,664
    What are you doing with the code?
    To go to the next record, use
    Code:
    r.MoveNext
    Usually there is a loop of some kind to loop through the recordset.


    If "fTxtCompany" is a field in the recordset "r", you would use
    Code:
    Debug.Print "fTxtCompany " & r!fTxtCompany
    or
    Code:
    Debug.Print "fTxtCompany " & r.("fTxtCompany")
    (this is from memory.....)

  3. #3
    orange's Avatar
    orange is offline Moderator
    Windows XP Access 2003
    Join Date
    Sep 2009
    Location
    Ottawa, Ontario, Canada; West Palm Beach FL
    Posts
    16,726
    You have to build a loop

    Code:
    pubLngProposalNo = [tbLngProposalNo]    '   get the current proposal number
        Dim d As DAO.Database
        Dim r As DAO.Recordset
        Dim strSQL As String
        strSQL = "SELECT tblProposal.fLngProposalNo, tblProposal.fTxtCompany " _
            & "From tblProposal " _
            & "WHERE (((tblProposal.fLngProposalNo)>= " & pubLngProposalNo & "));"
        Set r = CurrentDb.OpenRecordset(strSQL)
    
    do while not rs.eof
        Debug.Print "fTxtCompany " &   rs!fTxtCompany
    ''''do stuff in here
    rs.movenext
    Loop

  4. #4
    lawdy is offline Competent Performer
    Windows XP Access 2010 32bit
    Join Date
    Jan 2013
    Posts
    172
    That works great. Thanks very much

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

Similar Threads

  1. Replies: 5
    Last Post: 06-16-2013, 05:25 PM
  2. Replies: 32
    Last Post: 05-23-2013, 04:16 PM
  3. Replies: 6
    Last Post: 03-29-2013, 02:51 PM
  4. Replies: 1
    Last Post: 04-10-2012, 06:00 PM
  5. Replies: 1
    Last Post: 05-13-2010, 10:37 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