Results 1 to 8 of 8
  1. #1
    CP611 is offline Advanced Beginner
    Windows 10 Access 2016
    Join Date
    Nov 2017
    Posts
    55

    Using a Command Button to Send an email and Save New Data

    I have a button on my form that when you fill out all the information you press and it will save the information to the table and return the form to blank ready for the next entry. I also have a button that will send an email to the person filling it in with all the information on it so they have a record. So as it stands they have to press the email button then the submit button is there a way I can do this as one button so it submits the information to the table, returns the form to blank and sends an email? The submit button at the moment is done on a macro using the button wizard and save data and refresh.

  2. #2
    Join Date
    Jan 2017
    Location
    Swansea,South Wales,UK
    Posts
    4,940
    Use the email button to call the Submit button code?
    Please use # icon on toolbar when posting code snippets.
    Cross Posting: https://www.excelguru.ca/content.php?184
    Debugging Access: https://www.youtube.com/results?sear...bug+access+vba

  3. #3
    CP611 is offline Advanced Beginner
    Windows 10 Access 2016
    Join Date
    Nov 2017
    Posts
    55
    Hi there, how do I do that?

  4. #4
    Join Date
    Jan 2017
    Location
    Swansea,South Wales,UK
    Posts
    4,940
    You Call that item of code
    Call cmdSubmit_Click or whatever your button is called.
    Some people frown on doing that saying you put that code into it's own sub and call that from any place needed. Up to you.
    Please use # icon on toolbar when posting code snippets.
    Cross Posting: https://www.excelguru.ca/content.php?184
    Debugging Access: https://www.youtube.com/results?sear...bug+access+vba

  5. #5
    CP611 is offline Advanced Beginner
    Windows 10 Access 2016
    Join Date
    Nov 2017
    Posts
    55
    Hi there, thank you. Is that put at the top of the Send Email button? Below is the code that I currently have, would I put that piece of code that you have at the very top of this or under Private Sub Command28_Click(1)?

    Private Sub Command28_Click()


    Dim Msg As String

    Msg = "To " & AddedBy & ",<P>" & _
    "You have submitted the below information for " & TransactionDate & "<P>" & _
    "Transaction Type: " & TransactionType & "<P>" & _
    "Stock Category: " & StockCategory & "<P>" & _
    "Stock Description: " & StockDescription & "<P>" & _
    "Quantity: " & Quantity & "<P>" & _
    "Location: " & Location & "<P>" & _
    "If there is anything incorrect please inform the Warehouse Manager ASAP"


    Dim O As Outlook.Application
    Dim M As Outlook.MailItem

    Set O = New Outlook.Application
    Set M = O.CreateItem(olMailItem)

    With M
    .BodyFormat = olFormatHTML
    .HTMLBody = Msg
    .To = Email
    .Subject = "Stock Change to Warehouse"
    .Send
    End With

    Set M = Nothing
    Set O = Nothing

    End Sub

  6. #6
    Join Date
    Jan 2017
    Location
    Swansea,South Wales,UK
    Posts
    4,940
    Give your controls meaningful names, command28 is not going to mean much to anyone after a few months.
    Yes put it as the top. Perhaps some comment ad well to explain the code?
    Please use # icon on toolbar when posting code snippets.
    Cross Posting: https://www.excelguru.ca/content.php?184
    Debugging Access: https://www.youtube.com/results?sear...bug+access+vba

  7. #7
    CP611 is offline Advanced Beginner
    Windows 10 Access 2016
    Join Date
    Nov 2017
    Posts
    55
    Does it also make a different that on the submit button there isn't code, just an embedded on click macro?

  8. #8
    Join Date
    Jan 2017
    Location
    Swansea,South Wales,UK
    Posts
    4,940
    I did not use macroes except for batch purposes, too limiting.
    Look to see if you can run code from one.

    I would start using vba. There is some option somewhere to convert macroes to vba.
    Please use # icon on toolbar when posting code snippets.
    Cross Posting: https://www.excelguru.ca/content.php?184
    Debugging Access: https://www.youtube.com/results?sear...bug+access+vba

Please reply to this thread with any new information or opinions.

Similar Threads

  1. Replies: 3
    Last Post: 04-07-2022, 02:56 PM
  2. Email Form Data Using Command Button
    By Bebobrokstedy in forum Forms
    Replies: 1
    Last Post: 03-26-2020, 06:05 AM
  3. Replies: 4
    Last Post: 07-12-2018, 05:38 AM
  4. Create button to send email based on data in tbl
    By kiwikiki718 in forum Programming
    Replies: 12
    Last Post: 04-09-2017, 05:31 PM
  5. Command Button to Send Outlook Email
    By AJM229 in forum Forms
    Replies: 19
    Last Post: 05-07-2014, 09:05 AM

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts
  •  
Other Forums: Microsoft Office Forums