One possibility is to use the code here to get the network login name:
http://www.mvps.org/access/api/api0008.htm
The function is named fOSUserName(). To use it you could do something like
this in the form's Open event:
Private Sub Form_Open(Cancel As Integer)
Dim strUser as String
Dim blnOK as String
strUser = fOSUserName
' Debug.Print strUser
' MsgBox strUser
blnOK = (strUser = "YourLoginName")
cmdOne.Visible = blnOK
cndTwo.Visible = blnOK
End Sub
You could add either the Debug line or the MsgBox line to verify the
function is returning the expected value.
cmdOne and cmdTwo are command button's to open the forms.
Another option is to use a popup form in the Open event of a restricted
form:
DoCmd.OpenForm "frmPassword", , , , , acDialog
In frmPassword, a text box named txtPassword and a command button. In the
command button's Click event:
If Me.txtPassword = "YourPassword" Then
DoCmd.OpenForm "frmMain"
Else
MsgBox "Invalid password", vbInformation, "Password Error"
DoCmd.Close acForm, "frmMain"
End If
If you would need the code for more than one form you could pass the name of
the form in the OpenArgs argument of OpenForm:
Dim strFrm as String
strFrm = Me.Name
DoCmd.OpenForm "frmPassword", , , , , acDialog, strFrm
Then in the Click event on frmPassword:
Dim strArgs as String
strArgs = Me.OpenArgs
If Me.txtPassword = "YourPassword" Then
DoCmd.OpenForm strArgs
Else
MsgBox "Invalid password", vbInformation, "Password Error"
DoCmd.Close acForm, strArgs
End If
Please note that this will help keep honest people honest, nothing more.
The fOSUserName function is probably more secure. User Level Security is
better yet. I have found Jack MacDonald's security paper here to be of
great value in explaining how ULS works:
http://www.geocities.com/jacksonmacd/