Automatic Email

Haynesey

Registered User.
Local time
Today, 05:22
Joined
Dec 19, 2001
Messages
190
Hi, I have used the following code in a database. It opens an email fine but when I try and send it or close it, Access performs an illegal operation. Any ideas please?

Open "c:\TestFile.txt" For Input As #1
Do While Not EOF(1)
Line Input #1, strText
if FullText<>"" then FullText=FullText & vbcrlf
FullText=FullText & strText
Loop
Close #1

DoCmd.SendObject , , , "bukhix@mydomain.com", , , "OptionalSubject", _
FullText, True

Also, Is there anyway of the email being sent automatically without me having to click send and be able to have a combo box appear to select an email address?
 
Make sure you declare your variables like this:

Dim strText As String
Dim FullText As String

Open "c:\TestFile.txt" For Input As #1
Do While Not EOF(1)
Line Input #1, strText
If FullText <> "" Then FullText = FullText & vbCrLf
FullText = FullText & strText
Loop
Close #1

DoCmd.SendObject , , , "bukhix@mydomain.com", , , "OptionalSubject", _
FullText, True

Also be sure to replace the bukhix@mydomain.com with a valid email address and last of all the TestFile.txt needs to be in the C:\ before it can be brought into the email's body.
 
Thanks, I have added the extra line but it still performs illegal operations. Any more ideas? Also, is there anyway of being able to select the email address from a list in the database and be able to send it straight away without it opening for me to send or close it?
 
Just found out that it works when i put the following in:

Dim vbCrLf As String

However, then the text in the message it produces just blends together, anyway of left aligning it?
 
I have found a new fault. Whenever i try to change the name (Currently OptionalSubject), an illegal operation occurs again when the procedure runs.

DoCmd.SendObject , , , "bukhix@mydomain.com", , , "OptionalSubject", _
FullText, True
 
Thanks, I have added the extra line but it still performs illegal operations. Any more ideas? Also, is there anyway of being able to select the email address from a list in the database and be able to send it straight away without it opening for me to send or close it?

Yes there are a couple of different ways that you can get the address from the database. If your list is small (2 or 3) you can just put a combobox on the form and put your email addys with a value list. If you have several emails you could set the combo boxes source to the table that holds all your email addys. To send an email without looking at it you put a False at the end of the send object like this:

DoCmd.SendObject , , , "bukhix@nowhere.com", , , "No Subject", "No Text", False

Thanks, I have added the extra line but it still performs illegal operations. Any more ideas?

Have you checked for missing references? Open a new module and select Tools from the file menu. Open the references and see if any are marked missing. Have you been able to try this database on another computer? Is it small enough that you can remove any private information zip it up and send it to me so I can take a look at it?

Also the vbCrLf is a vb constant and shouldn't need dimming. Are you able to send a plain SendObject out without the problem. Start a new macro and build you a quick SendObject and then run it. Do you get the same error?

Let me know.


[This message has been edited by BukHix (edited 12-20-2001).]
 

Users who are viewing this thread

Back
Top Bottom