Results 1 to 5 of 5
  1. #1
    securitywyrm is offline Advanced Beginner
    Windows 7 64bit Access 2010 64bit
    Join Date
    Mar 2013
    Posts
    97

    Send an email with button click without locking the Access window?

    I have a button that opens an email to an employee, however when the email window is open the Access window can't be clicked until the email is either sent or closed. This is a problem, because I also want to click a button in Access to open a certain folder and drop that into the email.

    Here is my current code

    Code:
    Private Sub ButtonSentToFiscal_Click()
     Dim varName As Variant
    Dim varCC As Variant
    Dim varSubject As Variant
    Dim varBody As Variant
    varName = PacketEmail
    varCC = "V21sfcconference@va.gov"
    'separate each email by a ','
    varSubject = Me.Event & " packet approved"
    'Email subject
    varBody = Me.Identification & ", your conference/travel packet for " & Me.Event & " on " & Me.DateStart & " has been approved by the Office of the Director." & vbCrLf _
    & vbCrLf & "If your packet involves registration reimbursement, you will receive a reimbursement packet once a purchase order is generated. If your event is in a future fiscal quarter, the reimbursement packet will arrive in the first week of the quarter, otherwise it will arrive within two weeks of this email. Fiscal Quarters are October through December, January through March, April through June, and July through September." & vbCrLf & "If your packet involves travel reimbursement, the packet has been forwarded to the travel office which will contact you to arrange travel." & vbCrLf & vbCrLf & _
    "Office of Education" & vbCrLf & "V21SFCConference@va.gov"
    
    'Body of the email
    
    DoCmd.SendObject , , , varName, varCC, , varSubject, varBody, True, False
    'Send email command. The True after "varBody" allows user to edit email before sending.
    'The False at the end will not send it as a Template File
    Me.DateSentToFiscal = Date
    Me.Refresh
    End Sub
    As far as I can tell, what's happening is that while the email is still open, Access is still in the middle of executing a script and thus isn't available for activity. So perhaps what I need is for the script to not 'stop and wait' for the email, but rather proceed to the next step. What do I need to change?

    And yes, I know I need to get some error handling in there. Right now if I close the email, it gives a big warning message prompting to end or debug. That's next on my agenda.

  2. #2
    Gicu's Avatar
    Gicu is offline VIP
    Windows 8 Access 2013
    Join Date
    Jul 2015
    Location
    Kelowna, BC, Canada
    Posts
    4,115
    you should use Outlook automation to create your new email message instead of docmd.sendobject; after you display the message you can go back to Access or any other program to further edit it. There are lots of examples in this forum and on the web how to automate Outlook.

    Cheers,
    Vlad

  3. #3
    RuralGuy's Avatar
    RuralGuy is offline Administrator
    Windows 10 Access 2013 32bit
    Join Date
    Mar 2007
    Location
    8300' in the Colorado Rocky Mountains
    Posts
    12,922
    You need to take into account that Access is single threaded and so can only do one thing at a time in a very serial fashion.

  4. #4
    securitywyrm is offline Advanced Beginner
    Windows 7 64bit Access 2010 64bit
    Join Date
    Mar 2013
    Posts
    97
    Quote Originally Posted by Gicu View Post
    you should use Outlook automation to create your new email message instead of docmd.sendobject; after you display the message you can go back to Access or any other program to further edit it. There are lots of examples in this forum and on the web how to automate Outlook.

    Cheers,
    Vlad
    Is there a variant of DoCMD.sendobject so that it stops tracking that thread once it opens the email message? I do plan to properly automate it later, but since this is a work project I have to do the 'minimum time necessary to fix it."

  5. #5
    Gicu's Avatar
    Gicu is offline VIP
    Windows 8 Access 2013
    Join Date
    Jul 2015
    Location
    Kelowna, BC, Canada
    Posts
    4,115
    it is not a variant of Docmd.sendobject, it is an alternative way of creating a new email message that gives you a lot more control over it. Something similar to:

    Dim strBody As String

    Dim objOutlook As Object
    Dim objEmail As Object
    Dim strTo as string,strCC as string,strBcc as string

    Set objOutlook = CreateObject("Outlook.Application")
    Set objEmail = objOutlook.CreateItem(0)

    With objEmail
    .TO = varName
    .CC = varCC
    .Subject = varSubject
    .body=varbody
    .display

    End With

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

Similar Threads

  1. Send email window to top
    By LonghronJ in forum Modules
    Replies: 3
    Last Post: 01-10-2018, 03:32 PM
  2. Send Email on Click Decimal Formatiing
    By Lewis825 in forum Access
    Replies: 1
    Last Post: 05-10-2016, 06:44 AM
  3. Replies: 1
    Last Post: 09-07-2014, 10:15 PM
  4. Replies: 5
    Last Post: 05-07-2014, 09:25 AM
  5. Unable to open DB window on a Button click
    By ssashraf in forum Security
    Replies: 6
    Last Post: 12-12-2012, 12:39 PM

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