Permission to open database

  • Thread starter Thread starter Guest
  • Start date Start date
G

Guest

Hello, I want to be able to check the users PC login name on a "WelcomeForm"
against a field named loginID with names and if the users PC login name isnt
in the list in the table "tbl_LoginID" then they get a message stating they
do not have access to the database and the database closes. I already have a
"WelcomeForm" startup form that shows the users login name by using a test
box named Text_Network_User and its default value =FOSUserName() and a module
that gets the users login name andputs it in the Text_Network_User . That
works great! my problem is I want to run code on the "WelcomeForm" on open
event that would check the name thats in the Text_Network_User text box and
if its not in the tbl_LoginID field- LoginID then it closes the database.
Here is what I have so far and it keeps closing the database... Im a newbie
so please expalin... Thanks!

Private Sub Form_Open(Cancel As Integer)
'Check value of password in tblEmployees to see if this matches value chosen
in combo box

If Me.Text_Network_User.Value = DLookup("LoginID", "tbl_LoginID") Then

LoginID = Me.Text_Network_User.Value

'Close logon form and open Welcome screen

DoCmd.OpenForm "WelcomeForm"


Else
MsgBox "Access Denyed", vbOKOnly, "Invalid Entry!"
End If
Application.Quit
End Sub
 
If IsNull(DLookup("[loginID]", "[tbl_LoginID]", "[loginID] = '" &
Me.Text_Network_User & "'" Then
MsgBox "You are Not Authorized to Live on This Planet"
End If
 
Where would I put this code and delete mine? Thanks!


--
Newbies need extra loven.........


Klatuu said:
If IsNull(DLookup("[loginID]", "[tbl_LoginID]", "[loginID] = '" &
Me.Text_Network_User & "'" Then
MsgBox "You are Not Authorized to Live on This Planet"
End If
--
Dave Hargis, Microsoft Access MVP


Chad said:
Hello, I want to be able to check the users PC login name on a "WelcomeForm"
against a field named loginID with names and if the users PC login name isnt
in the list in the table "tbl_LoginID" then they get a message stating they
do not have access to the database and the database closes. I already have a
"WelcomeForm" startup form that shows the users login name by using a test
box named Text_Network_User and its default value =FOSUserName() and a module
that gets the users login name andputs it in the Text_Network_User . That
works great! my problem is I want to run code on the "WelcomeForm" on open
event that would check the name thats in the Text_Network_User text box and
if its not in the tbl_LoginID field- LoginID then it closes the database.
Here is what I have so far and it keeps closing the database... Im a newbie
so please expalin... Thanks!

Private Sub Form_Open(Cancel As Integer)
'Check value of password in tblEmployees to see if this matches value chosen
in combo box

If Me.Text_Network_User.Value = DLookup("LoginID", "tbl_LoginID") Then

LoginID = Me.Text_Network_User.Value

'Close logon form and open Welcome screen

DoCmd.OpenForm "WelcomeForm"


Else
MsgBox "Access Denyed", vbOKOnly, "Invalid Entry!"
End If
Application.Quit
End Sub
 
I forgot to mention I cant even ener this code it gives me a error

Compile error:
Expected: expression
--
Newbies need extra loven.........


Klatuu said:
If IsNull(DLookup("[loginID]", "[tbl_LoginID]", "[loginID] = '" &
Me.Text_Network_User & "'" Then
MsgBox "You are Not Authorized to Live on This Planet"
End If
--
Dave Hargis, Microsoft Access MVP


Chad said:
Hello, I want to be able to check the users PC login name on a "WelcomeForm"
against a field named loginID with names and if the users PC login name isnt
in the list in the table "tbl_LoginID" then they get a message stating they
do not have access to the database and the database closes. I already have a
"WelcomeForm" startup form that shows the users login name by using a test
box named Text_Network_User and its default value =FOSUserName() and a module
that gets the users login name andputs it in the Text_Network_User . That
works great! my problem is I want to run code on the "WelcomeForm" on open
event that would check the name thats in the Text_Network_User text box and
if its not in the tbl_LoginID field- LoginID then it closes the database.
Here is what I have so far and it keeps closing the database... Im a newbie
so please expalin... Thanks!

Private Sub Form_Open(Cancel As Integer)
'Check value of password in tblEmployees to see if this matches value chosen
in combo box

If Me.Text_Network_User.Value = DLookup("LoginID", "tbl_LoginID") Then

LoginID = Me.Text_Network_User.Value

'Close logon form and open Welcome screen

DoCmd.OpenForm "WelcomeForm"


Else
MsgBox "Access Denyed", vbOKOnly, "Invalid Entry!"
End If
Application.Quit
End Sub
 
Probably because you copied it and it was wrapped into multiple lines by the
newsreader. Plus Klaatu missed a closing parentheses.

If IsNull(DLookup("[loginID]", _
"[tbl_LoginID]", _
"[loginID] = '" & Me.Text_Network_User & "'")) Then
MsgBox "You are Not Authorized to Live on This Planet"
End If

Although my preference is this situation is to use DCount instead of
DLookup.

If DCount("*","tblLoginID","LoginID = '" & Me.Text_Network_User & "'") = 0
Then
MsgBox "Go home. You are wanted here."
End If

The above should be three lines of code. The first line starts with "IF"
and ends with "Then"

--
John Spencer
Access MVP 2002-2005, 2007
Center for Health Program Development and Management
University of Maryland Baltimore County
..

Chad said:
I forgot to mention I cant even ener this code it gives me a error

Compile error:
Expected: expression
--
Newbies need extra loven.........


Klatuu said:
If IsNull(DLookup("[loginID]", "[tbl_LoginID]", "[loginID] = '" &
Me.Text_Network_User & "'" Then
MsgBox "You are Not Authorized to Live on This Planet"
End If
--
Dave Hargis, Microsoft Access MVP


Chad said:
Hello, I want to be able to check the users PC login name on a
"WelcomeForm"
against a field named loginID with names and if the users PC login name
isnt
in the list in the table "tbl_LoginID" then they get a message stating
they
do not have access to the database and the database closes. I already
have a
"WelcomeForm" startup form that shows the users login name by using a
test
box named Text_Network_User and its default value =FOSUserName() and a
module
that gets the users login name andputs it in the Text_Network_User .
That
works great! my problem is I want to run code on the "WelcomeForm" on
open
event that would check the name thats in the Text_Network_User text box
and
if its not in the tbl_LoginID field- LoginID then it closes the
database.
Here is what I have so far and it keeps closing the database... Im a
newbie
so please expalin... Thanks!

Private Sub Form_Open(Cancel As Integer)
'Check value of password in tblEmployees to see if this matches value
chosen
in combo box

If Me.Text_Network_User.Value = DLookup("LoginID", "tbl_LoginID")
Then

LoginID = Me.Text_Network_User.Value

'Close logon form and open Welcome screen

DoCmd.OpenForm "WelcomeForm"


Else
MsgBox "Access Denyed", vbOKOnly, "Invalid Entry!"
End If
Application.Quit
End Sub
 
John I got it to work with the code below I got from an example I found. I
would also like to add an outlook window with my email address so they can
email me. I posted this question in the new users so it wouldnt get mixed up
with this one. Please look at it because I havent a clue on how to go about
implimenting this... Thanks!

Private Sub Form_Open(Cancel As Integer)

Dim db As DAO.Database
Dim rst As DAO.Recordset
Dim rstV As Recordset
Dim stDocName As String
Dim stLinkCriteria As String

Set db = CurrentDb()
Set rst = db.OpenRecordset("tbl_LoginID", dbOpenDynaset)

If Not IsNull(Me.Text_Network_User) Then
rst.FindFirst "strEmployeeUserID = '" & Me.Text_Network_User & "'" &
" And strEmployeeUserID = '" & Me.Text_Network_User & "'"

If rst.NoMatch Then
MsgBox "You do not have access to this database!!! " & Chr(13) & _
"Please contact the Database Adminstrator for assistance.",
vbOKOnly + vbCritical, "Logon Denied"
DoCmd.Quit

Else

stDocName = "WelcomeForm"
DoCmd.OpenForm stDocName, , , stLinkCriteria

End If

End If

End Sub

--
Newbies need extra loven.........


John Spencer said:
Probably because you copied it and it was wrapped into multiple lines by the
newsreader. Plus Klaatu missed a closing parentheses.

If IsNull(DLookup("[loginID]", _
"[tbl_LoginID]", _
"[loginID] = '" & Me.Text_Network_User & "'")) Then
MsgBox "You are Not Authorized to Live on This Planet"
End If

Although my preference is this situation is to use DCount instead of
DLookup.

If DCount("*","tblLoginID","LoginID = '" & Me.Text_Network_User & "'") = 0
Then
MsgBox "Go home. You are wanted here."
End If

The above should be three lines of code. The first line starts with "IF"
and ends with "Then"

--
John Spencer
Access MVP 2002-2005, 2007
Center for Health Program Development and Management
University of Maryland Baltimore County
..

Chad said:
I forgot to mention I cant even ener this code it gives me a error

Compile error:
Expected: expression
--
Newbies need extra loven.........


Klatuu said:
If IsNull(DLookup("[loginID]", "[tbl_LoginID]", "[loginID] = '" &
Me.Text_Network_User & "'" Then
MsgBox "You are Not Authorized to Live on This Planet"
End If
--
Dave Hargis, Microsoft Access MVP


:

Hello, I want to be able to check the users PC login name on a
"WelcomeForm"
against a field named loginID with names and if the users PC login name
isnt
in the list in the table "tbl_LoginID" then they get a message stating
they
do not have access to the database and the database closes. I already
have a
"WelcomeForm" startup form that shows the users login name by using a
test
box named Text_Network_User and its default value =FOSUserName() and a
module
that gets the users login name andputs it in the Text_Network_User .
That
works great! my problem is I want to run code on the "WelcomeForm" on
open
event that would check the name thats in the Text_Network_User text box
and
if its not in the tbl_LoginID field- LoginID then it closes the
database.
Here is what I have so far and it keeps closing the database... Im a
newbie
so please expalin... Thanks!

Private Sub Form_Open(Cancel As Integer)
'Check value of password in tblEmployees to see if this matches value
chosen
in combo box

If Me.Text_Network_User.Value = DLookup("LoginID", "tbl_LoginID")
Then

LoginID = Me.Text_Network_User.Value

'Close logon form and open Welcome screen

DoCmd.OpenForm "WelcomeForm"


Else
MsgBox "Access Denyed", vbOKOnly, "Invalid Entry!"
End If
Application.Quit
End Sub
 
Sorry about the missing ), Chad

Glad you got it working, but that is a very slow way to do it. The DLookup
will replace all that code:

Private Sub Form_Open(Cancel As Integer)

If IsNull(DLookup("[loginID]", "[tbl_LoginID]", "[loginID] = '" &
Me.Text_Network_User & "'" Then
MsgBox "You do not have access to this database!!! " & Chr(13) & _
"Please contact the Database Adminstrator for assistance.",
vbOKOnly + vbCritical, "Logon Denied"
DoCmd.Quit
End If
End Sub


--

--
Dave Hargis, Microsoft Access MVP


Chad said:
John I got it to work with the code below I got from an example I found. I
would also like to add an outlook window with my email address so they can
email me. I posted this question in the new users so it wouldnt get mixed up
with this one. Please look at it because I havent a clue on how to go about
implimenting this... Thanks!

Private Sub Form_Open(Cancel As Integer)

Dim db As DAO.Database
Dim rst As DAO.Recordset
Dim rstV As Recordset
Dim stDocName As String
Dim stLinkCriteria As String

Set db = CurrentDb()
Set rst = db.OpenRecordset("tbl_LoginID", dbOpenDynaset)

If Not IsNull(Me.Text_Network_User) Then
rst.FindFirst "strEmployeeUserID = '" & Me.Text_Network_User & "'" &
" And strEmployeeUserID = '" & Me.Text_Network_User & "'"

If rst.NoMatch Then
MsgBox "You do not have access to this database!!! " & Chr(13) & _
"Please contact the Database Adminstrator for assistance.",
vbOKOnly + vbCritical, "Logon Denied"
DoCmd.Quit

Else

stDocName = "WelcomeForm"
DoCmd.OpenForm stDocName, , , stLinkCriteria

End If

End If

End Sub

--
Newbies need extra loven.........


John Spencer said:
Probably because you copied it and it was wrapped into multiple lines by the
newsreader. Plus Klaatu missed a closing parentheses.

If IsNull(DLookup("[loginID]", _
"[tbl_LoginID]", _
"[loginID] = '" & Me.Text_Network_User & "'")) Then
MsgBox "You are Not Authorized to Live on This Planet"
End If

Although my preference is this situation is to use DCount instead of
DLookup.

If DCount("*","tblLoginID","LoginID = '" & Me.Text_Network_User & "'") = 0
Then
MsgBox "Go home. You are wanted here."
End If

The above should be three lines of code. The first line starts with "IF"
and ends with "Then"

--
John Spencer
Access MVP 2002-2005, 2007
Center for Health Program Development and Management
University of Maryland Baltimore County
..

Chad said:
I forgot to mention I cant even ener this code it gives me a error

Compile error:
Expected: expression
--
Newbies need extra loven.........


:

If IsNull(DLookup("[loginID]", "[tbl_LoginID]", "[loginID] = '" &
Me.Text_Network_User & "'" Then
MsgBox "You are Not Authorized to Live on This Planet"
End If
--
Dave Hargis, Microsoft Access MVP


:

Hello, I want to be able to check the users PC login name on a
"WelcomeForm"
against a field named loginID with names and if the users PC login name
isnt
in the list in the table "tbl_LoginID" then they get a message stating
they
do not have access to the database and the database closes. I already
have a
"WelcomeForm" startup form that shows the users login name by using a
test
box named Text_Network_User and its default value =FOSUserName() and a
module
that gets the users login name andputs it in the Text_Network_User .
That
works great! my problem is I want to run code on the "WelcomeForm" on
open
event that would check the name thats in the Text_Network_User text box
and
if its not in the tbl_LoginID field- LoginID then it closes the
database.
Here is what I have so far and it keeps closing the database... Im a
newbie
so please expalin... Thanks!

Private Sub Form_Open(Cancel As Integer)
'Check value of password in tblEmployees to see if this matches value
chosen
in combo box

If Me.Text_Network_User.Value = DLookup("LoginID", "tbl_LoginID")
Then

LoginID = Me.Text_Network_User.Value

'Close logon form and open Welcome screen

DoCmd.OpenForm "WelcomeForm"


Else
MsgBox "Access Denyed", vbOKOnly, "Invalid Entry!"
End If
Application.Quit
End Sub
 

Ask a Question

Want to reply to this thread or ask your own question?

You'll need to choose a username for the site, which only take a couple of moments. After that, you can post your question and our members will help you out.

Ask a Question

Back
Top