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
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