View Single Post
  #12   Report Post  
Posted to microsoft.public.excel.misc
Vikram Vikram is offline
external usenet poster
 
Posts: 11
Default Auto email from excel with custom subject

Hi Ron

I just figured out that, this works if I create a separate
commandbutton on the userform to send email. But as soon as I add this
code to the additem code (shown below) it starts playing up. It opens
email page fine, but the subject goes blank...and only shows default
text.

Is there any way, I could use a checkbox or something that will allow
me to do both the things : 1. Add record to the database 2) send email
with custom subject, with one commnd button instead of two?

cheers

================================================== ===========

Private Sub cmdAdd_Click()
Dim iRow As Long
Dim ws As Worksheet
Set ws = Worksheets("ComplaintData")

'find first empty row in database
iRow = ws.Cells(Rows.Count, 1) _
.End(xlUp).Offset(1, 0).Row


'copy the data to the database
ws.Cells(iRow, 1).Value = Me.txtcompno.Caption
ws.Cells(iRow, 2).Value = Me.txtdate.Caption
ws.Cells(iRow, 3).Value = Me.txtcustomer.Value
ws.Cells(iRow, 4).Value = Me.txtconper.Value
ws.Cells(iRow, 5).Value = Me.txtproduct.Value
ws.Cells(iRow, 6).Value = Me.txtbatch.Value
ws.Cells(iRow, 7).Value = Me.txtcategory.Value
ws.Cells(iRow, 8).Value = Me.txtdescription.Value
ws.Cells(iRow, 9).Value = Me.txtAM.Value

'clear the data
Me.txtcompno.Caption = ""
Me.txtcustomer.Value = ""
Me.txtconper.Value = ""
Me.txtproduct.Value = ""
Me.txtbatch.Value = ""
Me.txtcategory.Value = ""
Me.txtdescription.Value = ""
Me.txtAM.Value = ""

Dim OutApp As Object
Dim OutMail As Object
Dim strbody As String

Set OutApp = CreateObject("Outlook.Application")
Set OutMail = OutApp.CreateItem(0)

With OutMail
.To = "
.CC = ""
.BCC = ""
.Subject = "A new Complaint No." & Me.txtcompno.Caption & " has
been entered."
.Body = "A new Complaint No." & Me.txtcompno.Caption & " has
been entered for " & Me.txtcustomer.Value
.display 'or use .Display
End With

Set OutMail = Nothing
Set OutApp = Nothing
Unload Me

end sub
================================================== ===========