J
johnlute
Access 2003.
I found a 2008 post by Arvin Meyer and am having trouble with it:
I use the api code to identify the Windows authenticated username:
http://www.mvps.org/access/api/api0008.htm
and simply add the If statement to the form's code:
If fOSUserName() = "Arvin" Then
DoCmd.OpenForm stDocName, , , stLinkCriteria
Else
MsgBox "You are not allowed to use this form", vbOKOnly
DoCmd.CancelEvent
End If
I've created the fOSUserName module and used a similar If statement in
the command button that opens the form that I want:
Private Sub Command3_Click()
On Error GoTo Err_Command3_Click
Dim stDocName As String
Dim stLinkCriteria As String
stDocName = "frmEditSpecifications"
If fOSUserName() = "myusername" Then
DoCmd.OpenForm stDocName, , , stLinkCriteria
Else
MsgBox "Sorry! You are not allowed to use this form.",
vbCritical, vbOKOnly
DoCmd.CancelEvent
End If
Exit_Command3_Click:
Exit Sub
Err_Command3_Click:
MsgBox Err.Description
Resume Exit_Command3_Click
End Sub
This results in a compile error: expected variable or procedure, not a
module. The debugger points to > fOSUserName
If I change this from fOSUserName() to "fOSUserName" then it compiles
but when I click the button I get the not permitted message.
Two questions:
1. Was my correction correct?
2. If so, is it possible that my username isn't what I think it is?
Thanks for your help!
I found a 2008 post by Arvin Meyer and am having trouble with it:
I use the api code to identify the Windows authenticated username:
http://www.mvps.org/access/api/api0008.htm
and simply add the If statement to the form's code:
If fOSUserName() = "Arvin" Then
DoCmd.OpenForm stDocName, , , stLinkCriteria
Else
MsgBox "You are not allowed to use this form", vbOKOnly
DoCmd.CancelEvent
End If
I've created the fOSUserName module and used a similar If statement in
the command button that opens the form that I want:
Private Sub Command3_Click()
On Error GoTo Err_Command3_Click
Dim stDocName As String
Dim stLinkCriteria As String
stDocName = "frmEditSpecifications"
If fOSUserName() = "myusername" Then
DoCmd.OpenForm stDocName, , , stLinkCriteria
Else
MsgBox "Sorry! You are not allowed to use this form.",
vbCritical, vbOKOnly
DoCmd.CancelEvent
End If
Exit_Command3_Click:
Exit Sub
Err_Command3_Click:
MsgBox Err.Description
Resume Exit_Command3_Click
End Sub
This results in a compile error: expected variable or procedure, not a
module. The debugger points to > fOSUserName
If I change this from fOSUserName() to "fOSUserName" then it compiles
but when I click the button I get the not permitted message.
Two questions:
1. Was my correction correct?
2. If so, is it possible that my username isn't what I think it is?
Thanks for your help!