January 7th, 2013, 11:23 AM
[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.
The error is thrown on the line "Loop Until MailType <> "3" Or..."
If MailType <> "3" Then
Do Until MailType = "3" And Location = "Lubbock"
If MailType = "3" And Location = "Lubbock" Then
Call SendMail(r, d)
Loop Until MailType <> "3" Or Location <> "Lubbock"
ElseIf .EOF Then
MsgBox "E-mails sent."
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.
January 7th, 2013, 12:05 PM
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:
How it works:
' 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)
' Moves to the next record.
' Loop through this process until there are no more records.
Loop Until .EOF
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
Click Here to Expand Forum to Full Width
This is a Codeguru.com survey!