Hello all,

I am relatively new to Visual Basic and have managed to muttle my way through creating a 2013 Word document that has some ActiveX controls. The final control I put in place is a Command Button that, when clicked, it sends the form off to an email. That is all working great, however, I would like to have a pop-up message that displays after the button is clicked, letting the form sender know the form has actually been sent. I have put the code I used for this Command Button below. Any help would be much appreciated.

Private Sub CommandButton4_Click()
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 = "New Employee Account"
.Body = "New Employee Account Form is Attached!!"
.To = "emailaddress@domain.com"
.Importance = olImportanceHigh 'Or olImportanceNormal Or olImportanceLow
.Attachments.Add Doc.FullName
.Send
End With

Application.ScreenUpdating = True

Set Doc = Nothing
Set OL = Nothing
Set EmailItem = Nothing

End Sub

Recommended Answers

All 9 Replies

You can use MessageBox. There are 21 variations but the most basic is

Dim result = MessageBox.Show("one or more lines of text")

The value of result depends on how the box is closed. This, in turn, depends of which combination of buttons you specify. Check out the intellisense popup after you press the opening (.

Thank you.

Where would this line of code get entered into the code in my original post?

Did you try line 26?

I did try line 26 but got a compile error :(

commented: Usually that means a syntax error. Share your code. +15
Private Sub CommandButton4_Click()
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 = "New Employee Account"
.Body = "New Employee Account Form is Attached!!"
.To = "john.clancy@wvbk.com"
.Importance = olImportanceHigh 'Or olImportanceNormal Or olImportanceLow
.Attachments.Add Doc.FullName
.Send
End With

Application.ScreenUpdating = True

Set Doc = Nothing
Set OL = Nothing
Set EmailItem = Nothing
Dim result = MessageBox.Show("one or more lines of text")
End Sub

So why bother with Dim result if you are not going to use the result? Make your code simpler. Docs on that call are on the web so check your syntax.

I see you tagged this with both vb.net and visual-basic-6. The syntax for MessageBox differs between the two versions. Google "message box" with the version you are using to get the correct syntax. Based on the syntax of the line

Private Sub CommandButton4_Click()

I'll assume you are using vb6 in which case the syntax is

MsgBox(Prompt, [Buttons as VbMsgBoxStyle], [Title], [HelpFile], [Context]))

and you can get away with

MsgBox("The form has been sent")

Revered Jim, you answered my prayers! It works exactly as I was hoping. Thank you!!

Glad to help.

Be a part of the DaniWeb community

We're a friendly, industry-focused community of developers, IT pros, digital marketers, and technology enthusiasts meeting, networking, learning, and sharing knowledge.