VB & Lotus Notes

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

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
 

Excel Facts

How to calculate loan payments in Excel?
Use the PMT function: =PMT(5%/12,60,-25000) is for a $25,000 loan, 5% annual interest, 60 month loan.
Your code is written to display an "invalid subject" message if the recipient, OR subject OR body line is blank. It could be any of those 3 causing the problem, not just the subject.

Code:
'// 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
 
Upvote 0
I just tested this and it worked for me!

Did you have all the required information in?
 
Upvote 0

Forum statistics

Threads
1,221,904
Messages
6,162,744
Members
451,785
Latest member
DanielCorn

We've detected that you are using an adblocker.

We have a great community of people providing Excel help here, but the hosting costs are enormous. You can help keep this site running by allowing ads on MrExcel.com.
Allow Ads at MrExcel

Which adblocker are you using?

Disable AdBlock

Follow these easy steps to disable AdBlock

1)Click on the icon in the browser’s toolbar.
2)Click on the icon in the browser’s toolbar.
2)Click on the "Pause on this site" option.
Go back

Disable AdBlock Plus

Follow these easy steps to disable AdBlock Plus

1)Click on the icon in the browser’s toolbar.
2)Click on the toggle to disable it for "mrexcel.com".
Go back

Disable uBlock Origin

Follow these easy steps to disable uBlock Origin

1)Click on the icon in the browser’s toolbar.
2)Click on the "Power" button.
3)Click on the "Refresh" button.
Go back

Disable uBlock

Follow these easy steps to disable uBlock

1)Click on the icon in the browser’s toolbar.
2)Click on the "Power" button.
3)Click on the "Refresh" button.
Go back
Back
Top