Microsoft Office Forums

Go Back   Microsoft Office Forums > >

 
 
Thread Tools Display Modes
Prev Previous Post   Next Post Next
  #9  
Old 05-10-2016, 02:20 PM
derajlance derajlance is offline Disable email function of command button if all form fields are not completed Windows 10 Disable email function of command button if all form fields are not completed Office 2013
Novice
Disable email function of command button if all form fields are not completed
 
Join Date: May 2016
Posts: 18
derajlance is on a distinguished road
Default

Alright, I have my userform done and it is sending properly, but the code above to clear afterwards isn't working. It doesn't seem to be doing anything at all.

I am not sure if it is because I have the application set to not visible or what.
I am going to post my full code below in hopes that it may help someone to help me identify the issue. I want to either have the form clear and ready to be filled out and submitted again after the email is sent OR I want to completely exit the document so they have to open it again and start from scratch.

This document:
Code:
Sub AutoNew()
Application.Visible = False
UserForm1.Show
End Sub
UserForm1:
Code:
Private Sub UserForm1_Initialize()
Me.Caption = "Escalation"
Me.Label1.Caption = "SVM #:"
Me.Label2.Caption = "Claim #:"
Me.Label3.Caption = "Customer Name:"
Me.Label4.Caption = "Provider # and/or name:"
Me.Label5.Caption = "Reason for escalation:"
Me.CommandButton1.Caption = "Submit"
End Sub


Private Sub UserForm_Terminate()
Application.Quit SaveChanges:=False
End Sub

Private Sub CommandButton1_Click()

    Set SVM = ActiveDocument.Bookmarks("SVM").Range
    SVM.Text = Me.TextBox1.Value
    
    Set Claim = ActiveDocument.Bookmarks("Claim").Range
    Claim.Text = Me.TextBox2.Value
    
    Set Customer = ActiveDocument.Bookmarks("Customer").Range
    Customer.Text = Me.TextBox3.Value
    
    Set Provider = ActiveDocument.Bookmarks("Provider").Range
    Provider.Text = Me.TextBox4.Value
    
    Set Reason = ActiveDocument.Bookmarks("Reason").Range
    Reason.Text = Me.TextBox5.Value
    

Static running As Boolean
If running Then Exit Sub
If TextBox1 = "" Or TextBox2 = "" Or TextBox3 = "" Or TextBox4 = "" Or TextBox5 = "" Then MsgBox "All fields are required. Complete the form before clicking submit.": Exit Sub
running = True

Dim objOutlook As Object
Dim objOutlookMsg As Object
Dim objInspector As Object
Dim objDoc As Word.Document
Dim objRange As Range

    ActiveDocument.Content.Copy
    On Error Resume Next
    Set objOutlook = GetObject(, "Outlook.Application")
    If Err <> 0 Then
        MsgBox "Outlook is not running."
        GoTo lbl_Exit
    End If
    On Error GoTo 0

    Set objOutlookMsg = objOutlook.CreateItem(0)
    With objOutlookMsg
        .to = "email"
        .cc = "email"
        .Subject = "Escalation"
        Set objInspector = .GetInspector
        Set objDoc = objInspector.WordEditor
        Set objRange = objDoc.Range(0, 0)
        .Display
        objRange.Paste
        .send
    End With
lbl_Exit:
    Set objDoc = Nothing
    Set objRange = Nothing
    Set objOutlookMsg = Nothing
    Set objInspector = Nothing
    Set objOutlook = Nothing
    Exit Sub
End Sub
Reply With Quote
 



Similar Threads
Thread Thread Starter Forum Replies Last Post
Disable email function of command button if all form fields are not completed Email from Command Button derajlance Word VBA 6 05-05-2016 07:40 AM
Submit to Email Command Button rob7676 Word VBA 0 08-20-2015 05:05 AM
Disable email function of command button if all form fields are not completed command button that generates a popup for sending email oduntan Word VBA 4 03-21-2013 02:15 PM
Disable email function of command button if all form fields are not completed Command button - save in temp folder and send email with attachment bigbird69 Word VBA 13 11-18-2012 10:06 PM
Disable email function of command button if all form fields are not completed Word VBA: How to create a command button and trigger a function? tinfanide Word VBA 2 12-02-2011 05:51 AM

Other Forums: Access Forums

All times are GMT -7. The time now is 04:43 AM.


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