PC Review
Forums
Newsgroups
Microsoft Outlook
Microsoft Outlook Form Programming
Re: Make drop down field item read only based on user of form?
Forums
Newsgroups
Microsoft Outlook
Microsoft Outlook Form Programming
Re: Make drop down field item read only based on user of form?
![]() |
Re: Make drop down field item read only based on user of form? |
|
|
Thread Tools | Rate Thread |
|
|
#1 |
|
Guest
Posts: n/a
|
"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 |
|
|
|
#2 |
|
Guest
Posts: n/a
|
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 |
|
|
|
#3 |
|
Guest
Posts: n/a
|
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 |
|
|
|
#4 |
|
Guest
Posts: n/a
|
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. |
|
![]() |
|
| Thread Tools | |
| Rate This Thread | |
|
|

Main Page 

