Microsoft Office Forums

Go Back   Microsoft Office Forums > >

Reply
 
Thread Tools Display Modes
  #1  
Old 12-10-2023, 06:22 PM
lisamarie lisamarie is offline Cant get the submit button to open outlook Windows 11 Cant get the submit button to open outlook Office 2021
Novice
Cant get the submit button to open outlook
 
Join Date: Dec 2023
Posts: 1
lisamarie is on a distinguished road
Default Cant get the submit button to open outlook

I have created my submit button, and entered the following code, however the outlook is not opening, so I cant send my form

Private Sub SubmitButton1_Click()
Label1.Visible = True
Dim OL As Object
Dim EmailItem As Object
Dim Doc As Document

Application.ScreenUpdating = False
Set OL = CreateObject("Outlook.Application")
Set EmailItem = OL.CreateItem(olMailItem)
Set Doc = ActiveDocument
Doc.Save

With EmailItem
.Subject = "Complaint Form submitted"
.Body = "Please find attached complaint form"
.To = "dog.info@pncc.govt.nz"
.Importance = olImportanceNormal
.Attachments.Add Doc.FullName
.Send
End With

Application.ScreenUpdating = True



Set Doc = Nothing
Set OL = Nothing
Set EmailItem = Nothing
End Sub
Reply With Quote
  #2  
Old 12-11-2023, 01:49 AM
Guessed's Avatar
Guessed Guessed is offline Cant get the submit button to open outlook Windows 10 Cant get the submit button to open outlook Office 2016
Expert
 
Join Date: Mar 2010
Location: Canberra/Melbourne Australia
Posts: 3,977
Guessed has a brilliant futureGuessed has a brilliant futureGuessed has a brilliant futureGuessed has a brilliant futureGuessed has a brilliant futureGuessed has a brilliant futureGuessed has a brilliant futureGuessed has a brilliant futureGuessed has a brilliant futureGuessed has a brilliant futureGuessed has a brilliant future
Default

The code works on my machine so let's step through possible problems.
1. CreateObject 'could' be a problem if Outlook was already open. So you might tell vba to ignore errors and try getobject first and if no object is created, then use createobject
2. You can add DoEvents after opening the app to give it time to load before proceeding with the next steps
3. If you are using late binding to create the application then don't use variables that are only available when a reference is set to that application. olMailItem and olImportanceNormal should be replaced by their integer value.
__________________
Andrew Lockton
Chrysalis Design, Melbourne Australia
Reply With Quote
Reply



Similar Threads
Thread Thread Starter Forum Replies Last Post
Help with submit button to email form JoeFreeman Word VBA 1 01-28-2023 05:20 PM
VBA Code For Submit Button stu_c Word VBA 3 09-10-2018 04:37 AM
Cant get the submit button to open outlook Submit Button Req that populates email address phorsley Word VBA 1 10-17-2017 04:50 PM
Submit to Email Command Button rob7676 Word VBA 0 08-20-2015 05:05 AM
Cant get the submit button to open outlook VBA Code for a SUBMIT button in a Word form BlueMax Word VBA 3 08-07-2013 06:26 AM

Other Forums: Access Forums

All times are GMT -7. The time now is 08:42 AM.


Powered by vBulletin® Version 3.8.11
Copyright ©2000 - 2024, vBulletin Solutions Inc.
Search Engine Optimisation provided by DragonByte SEO (Lite) - vBulletin Mods & Addons Copyright © 2024 DragonByte Technologies Ltd.
MSOfficeForums.com is not affiliated with Microsoft