CommandButton to send a form

T

tmreyes

I want to add a command button to a form that will send or forward the form
contents after it has been filled out to a predetermined PDL and the person
that sent the form orginally. I am new to VB so looking for code examples.
thanks in advance.
 
K

Ken Slovak - [MVP - Outlook]

For information on all that to get you started look at www.outlookcode.com.
There's information there on Outlook forms, setting up buttons and working
with Outlook VBA macro code and COM addins.

For future reference please post the Outlook version you are using so the
appropriate answers can be provided.
 
T

tmreyes

Ken -
I created the form and published it to a personal folder. i have a command
button on the form. when i run the form and click the button the code behind
the button does not work but when i run the code in VB editor it works.
here is the code:
Sub CommandButton1_Click ()
Dim myolApp As Outlook.Application
Dim myinspector As Outlook.Inspector
Dim myItem As Outlook.MailItem
Dim myattachments As Outlook.Attachments
Set myolApp = CreateObject("Outlook.Application")
Set myinspector = myolApp.ActiveInspector
If Not TypeName(myinspector) = "Nothing" Then
Set myItem = myinspector.CurrentItem.Forward
myItem.Recipients.Add "Reyes, Mark M [IT]"
myItem.Send
Else
MsgBox "There is no active inspector."
End If
End Sub

any suggestions? thanks in advance
 
K

Ken Slovak - [MVP - Outlook]

You are trying to use VBA type code with VBScript, which won't work. VBS has
no As clauses, all variables are Variants. So comment out all those As
clauses. Never create an Outlook.Application object in form code, use the
intrinsic Application object, which is trusted (references to the item for
the form should be Item, also intrinsic and trusted).
 

Ask a Question

Want to reply to this thread or ask your own question?

You'll need to choose a username for the site, which only take a couple of moments. After that, you can post your question and our members will help you out.

Ask a Question

Top