email a report

  • Thread starter Thread starter Kraven
  • Start date Start date
K

Kraven

Guest
Hi,

i have a database and use a form to add data. i can print single records with a button. see below.


Private Sub Knop45_Click()

Dim strDocNaam As String
Dim strFilter As String
strDocNaam = "Storingen"
strFilter = "[Storings-ID] = Forms![Storingen aanmelden]![Storings-ID]"
DoCmd.OpenReport strDocNaam, acViewNormal, , strFilter

End Sub


i would also like to email this data but with data in the body of the email, not as an attachment. the email adres is in the form.

can somebody give me a hand? thanks in advance
 
Create a textbox on your form where you can enter the email address and call it txtEmailAddress. On the click event of a button add the following code


Private Sub Knop45_Click()

Dim strTextMessage As String

strTextMessage = strTextMessage & Me!YourTextBox1
strTextMessage = strTextMessage & Me!YourTextBox2
strTextMessage = strTextMessage & Me!YourTextBox3
strTextMessage = strTextMessage & Me!YourTextBox4
strTextMessage = strTextMessage & Me!YourTextBox5
DoCmd.SendObject acSendNoObject, , , Me!txtEmailAddress, , , "TitleOfEmail", strTextMessage, True

End Sub


Hope this helps

IMO
 
You would need to build the body content of the e-mail dynamically using VB code then use the sendobjectmethod
eg

Code:
Dim strBody as string, strSQL as string
Dim MyDb as DAO.database, MyRs as DAO.Recordset

StrSQL = "SELECT YourFields FROM tblName WHERE ID = " & Forms!FormName!IDControl

Set MyDb = CurrentDb
Set MyRs = MyDb.OpenRecordset(strSQL)

'Loop through All Fields in the Recordset
For IntX = 0 to MyRs.Fields.Count -1
strBody = StrBody & MyRs(IntX) & vbcrlf
next

'Send Email to recipient with body of strBody
DoCmd.SendObject , , , "recipient", , , "Subject", strBody

hth

edit: - go with IMO's as it will be easier to do
The example I have given is a little easier to change as you only need to change the SQL to send a different message.
 
Last edited:
ok thanks guys,

First i'll try Imo's.
i got an error after the first line of text. saying that he can't find Me!ADRES. if i try this with just Me!NAAM it works just fine
syntax error??



Private Sub Knop46_Click()

Dim strDocNaam As String
Dim strFilter As String
Dim strTextMessage As String

strTextMsg = strTextMsg & Me!NAAM
strTextMsg = strTextMsg & Me!ADRES
strTextMsg = strTextMsg & Me!POSTCODE
strTextMsg = strTextMsg & Me!PLAATS

DoCmd.SendObject acSendNoObject, , , "test@blabla.nl", Subject:=strMailSubject, MessageText:=strTextMsg


End Sub
 
Make sure that none of the values could be null. If there is a chance of that, change the line to this

strTextMsg = strTextMsg & Nz(Me!ADRES,"")

I would also consider adding &vbcrlf to each line to improve the formatting otherwise you'll have one long line of text - so it now becomes

strTextMsg = strTextMsg & Nz(Me!ADRES,"") & vbcrlf

(and the same for the other lines)
 
Double Trouble w/Email Button

Hi all - thanks for your tips on implementing email functionality to an Access form.

I've put it on a form and linked my VBA sub to a form button. I am able to get this button to work only once after I open the database file. From there on, everytime I click nothing happens. If I close and reopen my database, I can again send the form only once during my session.

Are there any additional lines of code I need to write to reset some kind of property?

Am using Access2K with a user-level-secured DB. Code I've written is as follows.

Private Sub btnEmailCall_Click()

Dim strTextMsg As String

strTextMsg = "You have just received a call that requires your attention!" & vbCrLf & vbCrLf

DoCmd.SendObject , , , "alexanderx@blah.com", , , "New Call", strTextMsg, False, ""

btnEmailCall_Click_Exit:
Exit Sub

Err_btnEmailCall_Click:
MsgBox "You have chosen to not send this email"
Resume btnEmailCall_Click_Exit

End Sub


Any assistance appreciated! TIA
 
The sendobject method does seem to have a few problems - I too have come across this on several occasions and not managed a fix. I now use the outlook object to send an email of which I have posted an example here
hth
 
Q145787 :::: Good for fax and e-mail

I had to do the same thing a few weeks ago. Microsoft's Knowledge base has a great article that gives you the code you need to accomplish this easily. The article number is Q145787. In the article, they explain how to Fax a record, all you need to do is change the code a little bit to make it work for you.

For example, when the code uses "DoCmd.SendObject acReport, "Invoice...", Just swap the fax number for the email address.

I know this works for Outlook, haven't tried it with Notes. Let me know how it works.

If I have some time later, I'll try to post the code for you.
 

Users who are viewing this thread

Back
Top Bottom