I am working on some code that will send an e-mail through Outlook 2003 "On Click" of a button inside of a form in my 2003 Access db. The code was in a different database, and was working just fine, but now that I have moved it into the new db, I am having problems. I have checked and changed form names several times, so I am sure that the error has nothing to do with that. It is throwing the flag on the line that actually sends the e-mail.
The e-mail sends just fine, and even includes the form I want as an attachment, but keep getting an error message titled "Run-time Error 2498" once VB runs through the code. As far as functionality goes, there is no problem, but this is certainly annoying, and would like for it to stop.
Any help is greatly appreciated.
Option Compare Database
' Chad Jackson
' 5-Day E-Mail Notification
' This program finds all tickets that have been out for 5 days or longer,
' and then sends an e-mail to a pre-defined list of people.
' The purpose of this program is to help ensure a 5-day ticket turnaround time.
Private Sub btnSendEmail_Click()
Dim rs As DAO.Recordset
Dim stDocName As String
Dim StrAttach As String
Set rs = CurrentDb.OpenRecordset("5-Day E-Mail Addresses")
If .EOF And .BOF Then ' If there are no records, the message from the next line will display.
MsgBox " No emails will be sent because there are no records from the query '5 Day Ticket Notification' "
Do Until .EOF ' Do until the end of the recordset
' The next line sends the E-Mail
DoCmd.SendObject acSendForm, "5 Day Ticket Notification", , ![E-Mail Address], , , "5-Day Reminder!", "Hello " & ![First Name] & ", " & Chr(10) & "You have tickets that have been out for 5 days or longer. Please get them processed as soon as possible.", False
.MoveNext ' Moves to the next record in the recordset
' Memory Clean Up
If Not rs Is Nothing Then
Set rs = Nothing
Sorry, forgot to specify in the code which line is causing problems.
It is the line that starts with, "DoCmd.SendObject acSendForm,..."
It comes directly after the comment " The next line sends the E-Mail"
Does it send the first one? Try to send ONE ONLY. Probably need to wait 15 seconds before sending another. Depending on Outlook, you might NOT be able to program it to send e-mails. Thank the spammers for that *feature*
But wait! It gets weirder...
I have another program that is almost identical to this, only it sends an email out for tickets that have been out for 10 days instead of 5. The code for the 10 day notification runs just fine, no error messages or flaws of any kind. The code looks almost identical, except it looks through a recordset titled "10-Day E-Mail Addresses" instead of the "5-Day E-Mail Addresses" this code looks through. Makes no sense to me.
Figured it out.
My table had an extra line item at the end with no data in it. VB was finding this "record" despite there being no data, and didn't know what to do with it, so it would throw that error. This explains why it would send to the other records in the table, yet still have an error.
Deleted the ghost line, and everything is running fine.
Thank you for your help!