Tek-Tips is the largest IT community on the Internet today!

Members share and learn making Tek-Tips Forums the best source of peer-reviewed technical information on the Internet!

  • Congratulations Wanet Telecoms Ltd on being selected by the Tek-Tips community for having the most helpful posts in the forums last week. Way to Go!

Problem with SendObject Funtion.

Status
Not open for further replies.

danvzla

Programmer
Jan 16, 2004
28
FI
Hi

I need to send an email with some information inserted on an Form. The body of the emal has to be like this:

ROCHELLE PARK

Date: 07/25/04 Time: 03:12 PM
User: dhenriqu

Tracking Number: A04NHPKOL10002_850_021104
Sites: 1234 1234 1234
Type of Error: HOPP PARAMETERS/ FREQ
Contacted Person: John Smith

Problem Description: This is the problem description

Solution: At the moment of generating this ticket there was no solution

This VBA code is working. It sends the email with the information I need, however, after sending some emails, it stop working. If I close access and open it again the program would start working againg. I think is because the complex way I'm doing the body of the message (BodyText var)


Function SendEmail()

Dim DistributionList As String
Dim SubjectText As String
Dim BodyText As String
Dim TrackingNumberVar As Variant
Dim BSCVar As Variant
Dim SitesVar As Variant
Dim MarketVar As Variant
Dim ErrorCatgVar As Variant
Dim ErrorDescripVar As Variant
Dim DateVar As Variant
Dim TimeVar As Variant
Dim CMEVar As Variant
Dim EditMsg As Variant
Dim ContactText As Variant

On Error Resume Next

CMEVar = Environ("Username")
DateVar = Me.DateText
TimeVar = Me.TimeText
TrackingNumberVar = Me.TNCombo
MarketVar = Me.MarketLabel.Value
SitesVar = Me.SiteCode
ErrorCatgVar = Me.ErrorCategCombo
ErrorDescripVar = Me.ErrorDescrip
EditMsg = Me.EditMsgCheck

If Me.SolutionDescrip = "" Then
SolutionDescripVar = " At the moment of generating this ticket there was no solution"
Else
SolutionDescripVar = Me.SolutionDescrip
End If

If MarketNotified = True Then
ContactText = vbCrLf & " Contacted Person: " &_ Me.ContactNotifed & " by " & Me.MarketNotifiedViaCombo
Else
ContactText = vbCrLf & " Contacted Person: Nobody on_ the market was inform about this problem"
End If

DistributionList = "daniel.smith@hotmail.com"
SubjectText = "SUBJECT"
BodyText = MarketVar & vbCrLf & vbCrLf & "Date:" & DateVar & "Time: " & TimeVar & vbCrLf & "User:" & CMEVar & vbCrLf & vbCrLf & "Tracking Number:" &_ TrackingNumberVar & vbCrLf & "Sites:" & SitesVar & vbCrLf & "Type of Error:" & ErrorCatgVar & ContactText & vbCrLf & vbCrLf & vbCrLf & "Problem Description: " & ErrorDescripVar & vbCrLf & vbCrLf & "Solution:" & SolutionDescripVar

DoCmd.SendObject ,, "DatafillErrorsForm_AWS", , DistributionList, , , SubjectText, BodyText, EditMsg

End Function

Any idea of what could be the problem? Do you know another way of doing this?

Thanx a lot for your help.

Dan
 
What program/version?

If it's Access, take a look at this SendObject method fails in Access 2000, which has one workaround, else take a look at the "mega thread" Thread702-396121. Perhaps also take a look at Nathan1967's two faq's in the same forum?

Roy-Vidar
 
it stop working
Some error message ?
First, you have some lines with syntax error at the continuation char _
Second, are you sure you don't reach a possible limit of 255 chars for BodyText ?
What happens if you comment out the On Error Resume Next instruction ?

Hope This Helps, PH.
Want to get great answers to your Tek-Tips questions? Have a look at FAQ219-2884 or FAQ222-2244
 
Hi.

Thanks. It looks like the problem is that I'm usinf Win2000. After 200 Char is starting to fail (no msg). So I change my code to shown below.. But it only send the msg when Outlook is open. How can I do to send it still if outlook is close.


Dim objOutlook As Outlook.Application
Dim objEmail As Outlook.MailItem

'***creates an instance of Outlook
Set objOutlook = CreateObject("Outlook.application")
Set objEmail = objOutlook.CreateItem(olMailItem)

'***creates and sends email
With objEmail
.To = DistributionList
.Subject = SubjectText
.Body = BodyText

If EditMsg = True Then

.Display

Else
.Save
.Send 'sends the email in Outlook. Change to DISPLAY if you want to be able to modify or see what you have created before sending the email

End If

End With

'**closes outlook
'objOutlook.Quit
Set objEmail = Nothing


Thanks

Dan


 
It does on my setup.

Perhaps quit Outlook and release the variables (would you have some instances of Outlook running if viewing the Task Manager)? Or try the GetObject function too, to get hold of an existing Outlook instance, if it exists?

What happens if you step thru the code line by line? (set a breakpoint on the first executable line (F9), then step (F8))

Roy-Vidar
 
Status
Not open for further replies.

Part and Inventory Search

Sponsor

Back
Top