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

    Why 'for next' works but 'while wend' does not

    Following is a partial function. The 'for next' methods works, but of course it only located 4 records (there are many more). The 'while when' methol freezes on line"If InvPaymentsRST.NoMatch = False Then". The for next code is:

    For i = 1 To 4
    InvPaymentsRST.FindNext "fDateReceived >= #" & datePaid & "#"
    If InvPaymentsRST.NoMatch = False Then
    Debug.Print InvPaymentsRST![fLngInvNo]
    Debug.Print InvPaymentsRST![fDateReceived]
    End If ' If Not InvPaymentsRST.NoMatch Then
    Next

    The while wend code is:

    While InvPaymentsRST.EOF = False
    InvPaymentsRST.FindNext "fDateReceived >= #" & datePaid & "#"


    If InvPaymentsRST.NoMatch = False Then ' #2
    Debug.Print InvPaymentsRST![fLngInvNo]
    Debug.Print InvPaymentsRST![fDateReceived]
    End If ' If Not InvPaymentsRST.NoMatch Then
    Wend

    Any help is appreciable.

  2. #2
    pbaldy's Avatar
    pbaldy is offline Who is John Galt?
    Windows XP Access 2007
    Join Date
    Feb 2010
    Location
    Nevada, USA
    Posts
    22,521
    If appropriate to the overall process, it would make more sense to open the recordset on an SQL statement that only pulled those records, then loop the recordset. Far more efficient to only pull needed records across the wire.
    Paul (wino moderator)
    MS Access MVP 2007-2019
    www.BaldyWeb.com

  3. #3
    lawdy is offline Competent Performer
    Windows XP Access 2010 32bit
    Join Date
    Jan 2013
    Posts
    172
    Yes, but is is a long process either way. I currently do it with 3 queries (there is a lot more to the process). I am trying to get it down to a one button process.

  4. #4
    pbaldy's Avatar
    pbaldy is offline Who is John Galt?
    Windows XP Access 2007
    Join Date
    Feb 2010
    Location
    Nevada, USA
    Posts
    22,521
    It sounds like the process would support it, so why not do it? Then your loop is a simple

    Do While Not InvPaymentsRST.EOF

    And you've made it more efficient by only pulling the necessary records.
    Paul (wino moderator)
    MS Access MVP 2007-2019
    www.BaldyWeb.com

  5. #5
    lawdy is offline Competent Performer
    Windows XP Access 2010 32bit
    Join Date
    Jan 2013
    Posts
    172
    I do it now using queries. I first query the current month's payments from the table with it link to another table which get the Invoice # and city name. Then I do a sum query to get the total amount for each location. Once this is done, still have to look up each location to get the city tax rate, city number, and the same info for transit taxes and any special taxes. This part would be very tricky for a query (for me anyway). That is why I am trying to do it with one button.

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

Similar Threads

  1. VBA works with a watch but not without it
    By TinaCa in forum Programming
    Replies: 0
    Last Post: 08-22-2011, 07:18 PM
  2. Works in one database, not a new one
    By Lorlai in forum Programming
    Replies: 3
    Last Post: 06-27-2011, 10:47 AM
  3. One works, the other doesn't. Why?
    By oleBucky in forum Queries
    Replies: 6
    Last Post: 05-09-2011, 01:52 PM
  4. Can someone explain how this works?
    By daveofgv in forum Access
    Replies: 3
    Last Post: 04-23-2011, 09:59 AM
  5. Ensuring Everything Works...?
    By catat in forum Access
    Replies: 1
    Last Post: 03-31-2010, 01:44 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