CodeGuru Home VC++ / MFC / C++ .NET / C# Visual Basic VB Forums Developer.com
Results 1 to 2 of 2
  1. #1
    Join Date
    Aug 2012
    Location
    Lubbock, TX
    Posts
    15

    [RESOLVED] Run Time Error '3021' : No Current Record

    I'm getting the infamous Run Time Error '3021', and am having no luck resolving the issue. I have browsed countless forums and tried many different solutions, but none of them have worked for me.
    This program is designed to send e-mails to appropriate people (determined by their field office location and "Mail Type"). It opens the recordset, loops through the records until it finds a person that matches BOTH criteria, sends the e-mail, and continues to loop through and sending messages to the appropriate people. The e-mails are sent through our smtp server to avoid the annoying Outlook security warnings.
    The program cycles through the records as it should, but when it gets to the EOF, it throws the error. I have stepped through the code numerous times to try and understand what the heck is going on, but I'm only getting frustrated.
    Code:
         With r
            If MailType <> "3" Then
                Do Until MailType = "3" And Location = "Lubbock"
                .MoveNext
                Loop
                If MailType = "3" And Location = "Lubbock" Then
                    Do
                    Call SendMail(r, d)
                    .MoveNext
                    Loop Until MailType <> "3" Or Location <> "Lubbock"
                End If
            ElseIf .EOF Then
                MsgBox "E-mails sent."
            End If
        End With
    The error is thrown on the line "Loop Until MailType <> "3" Or..."
    For each time it runs through the loop, I hold my mouse over the MailType and Location variables to check the values it is finding. When it gets to the EOF, the variables return no value (meaning it is as .EOF), but it still throws the error. It doesn't even make it to the ElseIf statement.
    The code runs PERFECTLY on my local hard drive, but when I try to run the code from the db that is saved on the server, the error is thrown. The code is identical, and the database is set up exactly the same. It is a mystery to me why it doesn't work on the server, but will on my PC.
    It may be that I have not set up my loops correctly, but I'm not sure. Any help/advice y'all can give me will be much appreciated.
    Thanks in advance.

  2. #2
    Join Date
    Aug 2012
    Location
    Lubbock, TX
    Posts
    15

    Re: Run Time Error '3021' : No Current Record

    I fixed my own problem, and made the code much simpler in the process. Double win!

    For anyone experiencing a similar problem, here is my solution:
    Code:
        With r
            Do
                ' If both criteria are met, send the e-mail.
                If MailType = "3" And Location = "Levelland" Then
                    ' The next line sends the e-mail.
                    Call SendMail(r, d)
                End If
            ' Moves to the next record.
            .MoveNext
            ' Loop through this process until there are no more records.
            Loop Until .EOF
        End With
    How it works:
    The "Do" initiates the loop, which will continue until .EOF (end of file). The program reads the first line in the recordset, and if both criteria are met, it calls the function that sends the e-mail message and then moves to the next record in the recordset. If either one of the criteria do not match, it kicks out of the "If" statement and moves to the next record. It continues this process until there are no more records in the recordset (.EOF). I set up the "If" statement within the loop so that each record is compared to the criteria.

Tags for this Thread

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts
  •  





Click Here to Expand Forum to Full Width

Featured