btrede
Board Regular
- Joined
- Oct 4, 2005
- Messages
- 87
Hello:
I been using the following code below for almost 6 months now. Now I am getting an error that there is not a valid subject. I do not know what happened.
What we did was create a template as a form that a user fills out. Once the user is done, we created this button that used the code below. Above the button is a drop down list of email addresses. The user selects the user to be emailed, clicks on the button, and it sends them an email telling them to continue setting up the part according to the form.
My only problem is that is says invalis subject, when there is a textbox which pops up and the subject is populated. I have tried making the subject the value of a cell, and I still get invalid subject.
could someone please look at my code and see if perhaps I am doing something wrong or something needs updating? I appreciate any help in advance:
Regards,
Bradley
I been using the following code below for almost 6 months now. Now I am getting an error that there is not a valid subject. I do not know what happened.
What we did was create a template as a form that a user fills out. Once the user is done, we created this button that used the code below. Above the button is a drop down list of email addresses. The user selects the user to be emailed, clicks on the button, and it sends them an email telling them to continue setting up the part according to the form.
My only problem is that is says invalis subject, when there is a textbox which pops up and the subject is populated. I have tried making the subject the value of a cell, and I still get invalid subject.
could someone please look at my code and see if perhaps I am doing something wrong or something needs updating? I appreciate any help in advance:
Regards,
Bradley
Code:
Sub Button105_Click()
' setting up various objects
Dim Maildb As Object
Dim UserName As String
Dim MailDbName As String
Dim MailDoc As Object
Dim attachME As Object
Dim Session As Object
Dim EmbedObj1 As Object
Dim recipient As String
Dim ccRecipient As String
Dim bccRecipient As String
Dim subject As String
Dim bodytext As String
Dim Attachment1 As String
' setting up all sending recipients
recipient = ThisWorkbook.Worksheets("Sheet1").Range("BF79").Value
ccRecipient = ""
bccRecipient = ""
subject = InputBox("Please enter the the item in which this form is representing?" _
, "Data Required", "MACPAC PART CREATION REF:")
bodytext = "Please access the MACPAC PART SET UP FORM ON THE P DRIVE YOUR INFORMATION. Please make sure to select the next person and click the send email button!"
'// Lets check to see if form is filled in Min req =Recipient, Subject, Body Text
If recipient = vbNullString Or subject = vbNullString Or bodytext = vbNullString Then
MsgBox "You have not entered a valid subject!", vbCritical + vbInformation
Exit Sub
End If
' creating a notes session
Set Session = CreateObject("Notes.NotesSession")
UserName = Session.UserName
MailDbName = Left$(UserName, 1) & Right$(UserName, (Len(UserName) - InStr(1, UserName, " "))) & ".nsf"
Set Maildb = Session.GETDATABASE("", MailDbName)
If Maildb.IsOpen <> True Then
On Error Resume Next
Maildb.OPENMAIL
End If
Set MailDoc = Maildb.CreateDocument
MailDoc.form = "Memo"
' loading the lotus notes e-mail with the inputed data
With MailDoc
.sendto = recipient
.copyto = ccRecipient
.blindcopyto = bccRecipient
.subject = subject
.body = bodytext
End With
' saving message
MailDoc.SaveMessageOnSend = True
Attachment1 = ThisWorkbook.Worksheets("Data").Range("ad1").Value
If Attachment1 <> "" Then
Set attachME = MailDoc.CREATERICHTEXTITEM("Attachment1")
Set EmbedObj1 = attachME.EMBEDOBJECT(1454, "", Attachment1, "Attachment")
MailDoc.CREATERICHTEXTITEM ("Attachment")
End If
' send e-mail !!!!
MailDoc.PostedDate = Now()
' if error in attachment or name of recipients
On Error GoTo errorhandler1
MailDoc.Send 0, recipient
Set Maildb = Nothing
Set MailDoc = Nothing
Set attachME = Nothing
Set Session = Nothing
Set EmbedObj1 = Nothing
'Unload Me
Exit Sub
' setting up the error message
errorhandler1:
MsgBox "Incorrect name supplied or the attachment has not attached," & _
"or your Lotus Notes has not opened correctly. Recommend you open up Lotus Notes" & _
"to ensure the application runs correctly and that a vaild connection exists"
Set Maildb = Nothing
Set MailDoc = Nothing
Set attachME = Nothing
Set Session = Nothing
Set EmbedObj1 = Nothing
' unloading the userform
'Unload Me
End Sub