Results 1 to 5 of 5
  1. #1
    mcfischer91 is offline Novice
    Windows XP Access 2007
    Join Date
    Jul 2014
    Posts
    6

    Having Trouble with Looping

    I have a code that is based on a query. Basically when I press the reports button, it is supposed to start with the first record, open the report based on the store number that's in the first column, and then send that in a pdf file. It's then supposed to move on to the next record and repeat the process. When I run it however, it sends the correct number of emails, but the information never seems to change from the first record, so it sends based on the email address and store number of what is in the first record. My code is below.



    Code:
    Private Sub Reports_Click()
    
    Dim MyDB As DAO.Database, RS As DAO.Recordset
    Dim Email As String
    Set MyDB = DBEngine.Workspaces(0).Databases(0)
    
    
    Set RS = MyDB.OpenRecordset _
        ("CMR Submits")
    
    
    RS.MoveLast
    RS.MoveFirst
    Do Until RS.EOF
        Email = Me.Email
        DoCmd.OpenReport "CMR Submit Store Report", acViewReport, , "[Store]=" & Me.Store__ & ""
        DoCmd.SendObject acSendReport, "CMR Submit Store Report", acFormatPDF, Email, , , "CMR Reports", , True
        RS.MoveNext
    Loop
    
    
    RS.Close
    MyDB.Close
    Set RS = Nothing
    Set MyDB = Nothing
    Close
    
    
    End Sub

  2. #2
    fredz is offline Novice
    Windows 7 64bit Access 2010 64bit
    Join Date
    Feb 2014
    Posts
    19
    It appears that you are looping thru a recordset (rs), but you are not using the recordset values.
    I think you want to use rs!Email instead of Me.Email, and rs!Store instead of Me.Store.
    Fred

  3. #3
    mcfischer91 is offline Novice
    Windows XP Access 2007
    Join Date
    Jul 2014
    Posts
    6
    When I change to RS!Store_#, I get an error <Item Not Found in this Collection> I know that it is definitely in the query in that syntax.

  4. #4
    June7's Avatar
    June7 is online now VIP
    Windows 7 64bit Access 2010 32bit
    Join Date
    May 2011
    Location
    The Great Land
    Posts
    53,632
    Should not use spaces or special characters/punctuation (underscore is exception) in naming convention. Better would be Store_Num or StoreNum.

    Try:

    rs![Store_#]

    or

    rs.Fields("[Store_#]")
    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.

  5. #5
    mcfischer91 is offline Novice
    Windows XP Access 2007
    Join Date
    Jul 2014
    Posts
    6
    Yeah I did that before I realized I was going to be using it for any coding. I changed it to just store and.....it works! Thanks a bunch you guys are great!

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

Similar Threads

  1. Looping
    By ddrew in forum Forms
    Replies: 8
    Last Post: 10-08-2012, 01:48 AM
  2. Looping query
    By jaykappy in forum Queries
    Replies: 13
    Last Post: 02-24-2012, 03:05 PM
  3. Looping Search
    By srmezick in forum Forms
    Replies: 5
    Last Post: 11-04-2011, 11:13 AM
  4. Looping in Access
    By ducthang88 in forum Programming
    Replies: 2
    Last Post: 12-04-2010, 07:43 PM
  5. Looping through a tbl to find a certain value
    By cwf in forum Programming
    Replies: 1
    Last Post: 05-17-2010, 04:02 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