PC Review Forums Newsgroups Microsoft Outlook Microsoft Outlook Form Programming Re: Make drop down field item read only based on user of form?

Reply

Re: Make drop down field item read only based on user of form?

 
Thread Tools Rate Thread
Old 30-06-2003, 01:13 PM   #1
Max Beesley
Guest
 
Posts: n/a
Default Re: Make drop down field item read only based on user of form?


"Munsifali Rashid" <mun@**RemoveToReply**vefuk.com> wrote in message news:<uqjCiKMPDHA.2160@TK2MSFTNGP11.phx.gbl>...
> Strange. Do you get a line number for that error?


No, but a debugging thingy opens and it highlights line 13 "set oDropdown..."

Sub Item_Open()

'String of usernames allowed to access the dropdown
'(Not sure if you can use constants in a sub)
Dim ALLOWED_USERS: ALLOWED_USERS = "maxb;maxc"

'Get the form
Dim oForm
Set oForm = Item.GetInspector.ModifiedFormPages("LocationMod2")

'Get the dropdown
Dim oDropdown
Set oDropdown = oForm.Controls("DDStatus")

'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

'Assume user is not authorised
Dim isAuthorised: isAuthorised = False

'Now check if the username is in the list, and if so, update isAuthorised value
If (InStr(1, ALLOWED_USERS, strUsername) > 0) Then isAuthorised = True

'Now update the readonly status of the dropdown
oDropdown.ReadOnly = (Not isAuthorised)

'Clean up
Set oDropdown = Nothing
Set oForm = Nothing

End Sub
  Reply With Quote
Old 03-07-2003, 11:11 AM   #2
Munsifali Rashid
Guest
 
Posts: n/a
Default Re: Make drop down field item read only based on user of form?

Make sure that your control names are correct.

For this example to work, your form page must be called "LocationMod2" (this
will be on the tab), and the dropdown name must be "DDStatus". As far as I
know, the names are not case sensitive.

Try the following code, which has error catching:


Sub Item_Open()

'String of usernames allowed to access the dropdown
Const ALLOWED_USERS = "maxb;maxc"

'Define control names
Const FORM_NAME = "LocationMod2"
Const DD_NAME = "DDStatus"

'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 dropdown
Dim oDropdown
Set oDropdown = oForm.Controls(DD_NAME)
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

'Assume user is not authorised
Dim isAuthorised: isAuthorised = False

'Now check if the username is in the list, and if so, update
isAuthorised value
If (InStr(1, ALLOWED_USERS, strUsername) > 0) Then isAuthorised = True

'Now update the readonly status of the dropdown
oDropdown.ReadOnly = (Not isAuthorised)

'Clean up
Set oDropdown = Nothing
Set oForm = Nothing

End Sub


Hope this helps.

Mun



  Reply With Quote
Old 08-07-2003, 01:37 PM   #3
Max Beesley
Guest
 
Posts: n/a
Default Re: Make drop down field item read only based on user of form?

BINGO!

I didn't need to run the error handling code, as your first sentence
suddenly clicked together. I was using the form name (i.e. what I
publish it as) rather than the tab label on the actual modified form.
My tab label was 'LocationHandlingProblem' which when inserted
correctly at the line worked fine.
I can now control read-only-ness of fields!

Thank you for all your help and perseverance.

"Munsifali Rashid" <mun@**RemoveToReply**vefuk.com> wrote in message news:<uPhejQVQDHA.2312@TK2MSFTNGP12.phx.gbl>...
> Make sure that your control names are correct.
>
> For this example to work, your form page must be called "LocationMod2" (this
> will be on the tab), and the dropdown name must be "DDStatus". As far as I
> know, the names are not case sensitive.
>
> Try the following code, which has error catching:
>
>
> Sub Item_Open()
>
> 'String of usernames allowed to access the dropdown
> Const ALLOWED_USERS = "maxb;maxc"
>
> 'Define control names
> Const FORM_NAME = "LocationMod2"
> Const DD_NAME = "DDStatus"
>
> '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 dropdown
> Dim oDropdown
> Set oDropdown = oForm.Controls(DD_NAME)
> 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
>
> 'Assume user is not authorised
> Dim isAuthorised: isAuthorised = False
>
> 'Now check if the username is in the list, and if so, update
> isAuthorised value
> If (InStr(1, ALLOWED_USERS, strUsername) > 0) Then isAuthorised = True
>
> 'Now update the readonly status of the dropdown
> oDropdown.ReadOnly = (Not isAuthorised)
>
> 'Clean up
> Set oDropdown = Nothing
> Set oForm = Nothing
>
> End Sub
>
>
> Hope this helps.
>
> Mun

  Reply With Quote
Old 10-07-2003, 12:53 PM   #4
Munsifali Rashid
Guest
 
Posts: n/a
Default Re: Make drop down field item read only based on user of form?

Brilliant. Good to hear it worked :-)

Mun



"Max Beesley" <maxbeesley@hotmail.com> wrote in message
news:559259c2.0307080537.568afcb@posting.google.com...
> BINGO!
>
> I didn't need to run the error handling code, as your first sentence
> suddenly clicked together. I was using the form name (i.e. what I
> publish it as) rather than the tab label on the actual modified form.
> My tab label was 'LocationHandlingProblem' which when inserted
> correctly at the line worked fine.
> I can now control read-only-ness of fields!
>
> Thank you for all your help and perseverance.



  Reply With Quote
Reply



Thread Tools
Rate This Thread
Rate This Thread:

Posting Rules
You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts

vB code is On
Smilies are On
[IMG] code is On
HTML code is Off