Tek-Tips is the largest IT community on the Internet today!

Members share and learn making Tek-Tips Forums the best source of peer-reviewed technical information on the Internet!

  • Congratulations gkittelson on being selected by the Tek-Tips community for having the most helpful posts in the forums last week. Way to Go!

How can I make this code look at more than just Mitch when logging in?

Status
Not open for further replies.

chubby

Programmer
Apr 28, 2001
278
US
Private Sub Form_Open(Cancel As Integer)
On Error GoTo ErrFO
If CurrentUser()<> &quot;Mitch&quot; Then
MsgBox &quot;Permission denied.&quot;, vbCritical, &quot;Security Check.&quot;
Cancel = True
End If
ExitFO:
Exit Sub
ErrFO:
MsgBox Err.Description, vbInformation, &quot;Form Open Error.&quot;
Resume ExitFO
End Sub
 
I'm assuming by &quot;look at&quot; you mean allow a user other than Mitch to access the resource. If that's the case, you could try a Select case statement:
[tt]
Select Case CurrentUser()
Case &quot;Mitch&quot;
'Continue opening form
Case &quot;Someone Else&quot;
'Continue opening form
Case Else
MsgBox &quot;Permission denied.&quot;, vbCritical, &quot;Security Denied&quot;
End Select[/tt]
(...this is just a general structure, I didn't check for syntax errors)

I think an easier, faster way of doing this would be to validate the username before the form was opened, like in the on_click event of a button used to open the form.
 
Create a list of &quot;acceptable&quot; users

For Idx = 0 to ubound(UserList)
[tab]If (CurrentUser = UserList(Idx)) then
[tab][tab]UserFlg = True
[tab][tab]Exit For
[tab]End If
Next Idx

If (UserFlag) then
[tab]'Open Form code goes here
Else
[tab]MsgBox &quot;Permission denied.&quot;, vbCritical, &quot;Security Check.&quot;
[Tab]Cancel = True
End If


MichaelRed
redmsp@erols.com

There is never time to do it right but there is always time to do it over
 
Status
Not open for further replies.

Part and Inventory Search

Sponsor

Back
Top