securing a form

  • Thread starter Thread starter joe
  • Start date Start date
J

joe

Hello,
I have been looking at a lot of the posts here trying to
find the answer to this question. unfortunately i have
not found it yet.

what i am trying to do is create logon box for two forms
on my databse. i was thinking i could just do it on the
onload property. if i can then that would be great i am
not trying to lock out any true computer gurus all i am
trying to do is prevent accidental deletion or updating.
so if anyone knows of something simple and effective
enough to allow what i am asking it would be appreciated.
thank you for everything.
joe

i have asked a lot of questions to the access.newsgroup
section and never have i been let down.
 
Hello,

My solution would be create a table of users and check the current login
name against the table. If the user is found then open the form, if not
close it. Step would be:

1. Creat a table called tblValidUsers with2 columns; UserName and
FormName. Enter users and names as applicable.

2. Add the code example found at
http://www.mvps.org/access/api/api0008.htm. into a General Module. This
will return the current login name.

3. Enter code like the following into a General Module:

Public Function ValidateUser(frmName As String) As Boolean
Dim db As DAO.Database
Dim rs As DAO.Recordset
Dim strSQLText As String
Set db = CurrentDb
strSQLText = "SELECT tblValidUsers.FormName" & vbCrLf
strSQLText = strSQLText & " , tblValidUsers.UserName" & vbCrLf
strSQLText = strSQLText & " FROM tblValidUsers" & vbCrLf
strSQLText = strSQLText & " WHERE (((tblValidUsers.FormName)='" &
frmName & "') " & vbCrLf
strSQLText = strSQLText & " AND ((tblValidUsers.UserName)='" &
fOSUserName() & "'));"
Set rs = db.OpenRecordset(strSQLText)
If Not rs.EOF Then
ValidateUser = True
Else
ValidateUser = False
End If
rs.Close

End Function

4. Enter the following code into the form's open event:

Private Sub Form_Open(Cancel As Integer)
If Not ValidateUser(Me.Name) Then
MsgBox "Your name is not vallid", vbInformation, "Closing form"
Cancel = True
End If
End Sub

HTH

--

Cheers
Mark

Free Access/Office Add-Ins at:
http://mphillipson.users.btopenworld.com/
 
worked exactly like i wanted. thank you very much.

seems straight forward also.
i really do appreciate the help this community has
provided.
-----Original Message-----
Hello,

My solution would be create a table of users and check the current login
name against the table. If the user is found then open the form, if not
close it. Step would be:

1. Creat a table called tblValidUsers with2 columns; UserName and
FormName. Enter users and names as applicable.

2. Add the code example found at
http://www.mvps.org/access/api/api0008.htm. into a General Module. This
will return the current login name.

3. Enter code like the following into a General Module:

Public Function ValidateUser(frmName As String) As Boolean
Dim db As DAO.Database
Dim rs As DAO.Recordset
Dim strSQLText As String
Set db = CurrentDb
strSQLText = "SELECT tblValidUsers.FormName" & vbCrLf
strSQLText = strSQLText & " ,
tblValidUsers.UserName" & vbCrLf
strSQLText = strSQLText & " FROM tblValidUsers" & vbCrLf
strSQLText = strSQLText & " WHERE
(((tblValidUsers.FormName)='" &
 
Back
Top