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 = "oxhb@manbw.dk"
'Set the recipient for a copy
'.CC = "recipient2@mail.com"
'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.Y.M. Wong-A-Ton - 15 Mar 2006 16:05 GMT
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.
---
S.Y.M. Wong-A-Ton
> 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.
[quoted text clipped - 59 lines]
>
> End Sub