VBscript errors

  • Thread starter Thread starter Guest
  • Start date Start date
G

Guest

Using an example from a post, I'm trying to tweak this code to work with my
situation.

I only want specific people to be able to edit fields on my form.

I get a 'unterminated line error' on line 21.

I'm really trying to learn vbscript on the fly, so please be patient with my
questions and silly mistakes.

Here's my form:

Sub Item_Open()

'String of usernames allowed to access administrative fields
Const ALLOWED_USERS = "gren;zeiram"

'Define control names
Const FORM_NAME = "Provider Add/Change Form"
Const FIELD_NAME1 = "groupdate"
Const FIELD_NAME2 = "groupcastenter"
Const FIELD_NAME3 = "imagedate"
Const FIELD_NAME4 = "imagecastenter"



'Handle errors
On Error Resume Next

'Get the form
Dim oForm: Set oForm = Item.GetInspector.ModifiedFormPages(FORM_NAME)
If (Err.Number <> 0) Then
Call MsgBox("Could not find form named '" & FORM_NAME & "'. Please
check and try again", vbCritical, "Error")
Exit Sub
End If

'Get the fields
Dim oField1,
Set oField1 = oForm.Controls(FIELD_NAME1),
Dim oField2,
Set oField2 = oForm.Controls(FIELD_NAME2),
Dim oField3,
Set oField3 = oForm.Controls(FIELD_NAME3),
Dim oField4,
Set oField4 = oForm.Controls(FIELD_NAME4),

If (Err.Number <> 0) Then
Call MsgBox("Could not find control named '" & DD_NAME & "'. Please
check and try again", vbCritical, "Error")
Exit Sub
End If

'Get the username of the windows user currently logged in
Dim oWsNetwork: Set oWsNetwork = CreateObject("WScript.Network")
Dim strUsername: strUsername = oWsNetwork.UserName
Set oWsNetwork = Nothing
If (Err.Number <> 0) Then
Call MsgBox("Error occured when trying to get windows username",
vbCritical, "Error")
Exit Sub
End If
 
Which is line 21? It's hard to tell in newsgroup posts, since extra line
feeds may creep in. But I think the problem may be with the lines where you
put two statements on one line separated with a colon. Try putting the
statements on separate lines.
 
new error: Unexpected 'End' Line 48

Sub Item_Open()

'String of usernames allowed to access administrative fields
Const ALLOWED_USERS = "dcoffin;tmarques"

'Define control names
Const FORM_NAME = "Provider Add/Change Form"
Const FIELD_NAME1 = "groupdate"
Const FIELD_NAME2 = "groupcastenter"
Const FIELD_NAME3 = "imagedate"
Const FIELD_NAME4 = "imagecastenter"



'Handle errors
On Error Resume Next

'Get the form
Dim oForm: Set oForm = Item.GetInspector.ModifiedFormPages(FORM_NAME)
If (Err.Number <> 0) Then
Call MsgBox("Could not find form named '" & FORM_NAME & "'. Please
check and try again", vbCritical, "Error")
Exit Sub
End If

'Get the fields
Dim oField1
Set oField1 = oForm.Controls(FIELD_NAME1)
Dim oField2
Set oField2 = oForm.Controls(FIELD_NAME2)
Dim oField3
Set oField3 = oForm.Controls(FIELD_NAME3)
Dim oField4
Set oField4 = oForm.Controls(FIELD_NAME4)

If (Err.Number <> 0) Then
Call MsgBox("Could not find control named '" & DD_NAME & "'. Please
check and try again", vbCritical, "Error")
Exit Sub
End If

'Get the username of the windows user currently logged in
Dim oWsNetwork: Set oWsNetwork = CreateObject("WScript.Network")
Dim strUsername: strUsername = oWsNetwork.UserName
Set oWsNetwork = Nothing
If (Err.Number <> 0) Then
Call MsgBox("Error occured when trying to get windows username",
vbCritical, "Error")
Exit Sub
End If
 
And line 48 is which line?

--
Sue Mosher, Outlook MVP
Author of
Microsoft Outlook Programming - Jumpstart for
Administrators, Power Users, and Developers
 
The absolute last line



Sue Mosher said:
And line 48 is which line?

--
Sue Mosher, Outlook MVP
Author of
Microsoft Outlook Programming - Jumpstart for
Administrators, Power Users, and Developers
 
You have no End Sub.

--
Sue Mosher, Outlook MVP
Author of
Microsoft Outlook Programming - Jumpstart for
Administrators, Power Users, and Developers
 
Thanks Sue!

Sue Mosher said:
You have no End Sub.

--
Sue Mosher, Outlook MVP
Author of
Microsoft Outlook Programming - Jumpstart for
Administrators, Power Users, and Developers
 
Back
Top