Log in

View Full Version : Add record and send email on same click of button in form



NoGoodAtCode
09-07-2014, 04:14 PM
Hi everyone,

Here is the info the parent thread instructed me to provide.

1. Version of the program

Office 2010


2. What you want it to do

On the single click of a button in a form, I would like it to add the new record and send the record in an email to adynamic email address taken from an input in the form.


3. Cell references, bookmark names, column letters, row numbers, worksheets, styles, whatever pertains to the information at hand


The table the form is built from is:

Assignment

The field names are:
User IDFK (Email Address)
Project IDFK
Task IDFK
Assignent Date (Not listed in the form)


4. Error messages if any

No errors, I just need to know what code to insert.


5. If not the entire code, then at least some of it


Private Sub CreateProjectButton_Click()


DoCmd.GoToRecord


End Sub


6. Sample data (before and after sample worksheets, add as attachments here)

Not sure what to include here


7. Politeness and gratitude :)

You guys are great!


8. Mark your thread solved, when it has been, by hitting the Thread Tools dropdown at the top of the thread.

Will do

jonh
09-08-2014, 01:27 AM
Private Sub CreateProjectButton_Click()
'add a new record
DoCmd.GoToRecord acDataForm, Me.Name, acNewRec

'add some data
Randomize
User = Environ("username")
Project = "Project " & CInt(Int((10000 * Rnd()) + 1))
Task = "Task " & CInt(Int((10000 * Rnd()) + 1))

'save record
Me.Dirty = False

'send email
'www.peterssoftware.com/c_emfa.htm
DoCmd.SendObject , , , User & "@myco.com", , , "More Spam", Project & vbCrLf & Task

End Sub