Infopath and programming with VBS. Help me please....

O

obirch

I have the following code, which I try to place in a Button Control under
Edit Form Code. The form is set to VBS coding.
When I try to use Preview Form, i get the error

"InfoPath cannot open the selected form because of an error in the form's
code.
The following error occurred:

Expected end of statement
File:script.vbs
Line:22
Dim bStarted As Boolean"

I don't understand why I get this error, could some one help me please?

The code...........
-------------------------------------------------------------------------------
Sub CTRL1_5_OnClick(eventObj)
' Write your code here

Dim bStarted As Boolean '<<== This is where I get the error
Dim oOutlookApp As Outlook.Application
Dim oItem As Outlook.MailItem

On Error Resume Next

If Len(ActiveDocument.Path) = 0 Then
MsgBox "Document needs to be saved first"
Exit Sub
End If

Set oOutlookApp = GetObject(, "Outlook.Application")
If Err <> 0 Then
Set oOutlookApp = CreateObject("Outlook.Application")
bStarted = True
End If

Set oItem = oOutlookApp.CreateItem(olMailItem)

With oItem
'Set the recipient
.To = "(e-mail address removed)"
'Set the recipient for a copy
'.CC = "(e-mail address removed)"
'Set the subject
.Subject = "New subject"
'The content of the document is used as the body for the email
.Body = "Info"
'Add the document as an attachment, you can use the .displayname property
'to set the description that's used in the message
'.Attachments.Add Source:=ActiveDocument.FullName, Type:=olByValue, _
' DisplayName:="Document as attachment"
.Send
End With

If bStarted Then
oOutlookApp.Quit
End If

Set oItem = Nothing
Set oOutlookApp = Nothing

End Sub
 
S

S.Y.M. Wong-A-Ton

Remove all the "As..." declarations. VBScript does not know typed data. So
instead of

Dim bStarted As Boolean

use

Dim bStarted

Do the same for all the other variable declarations.
 

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