Solved

Auto Open Form on Startup with condition

Posted on 2010-11-30
2
631 Views
Last Modified: 2012-05-10
I have a form that automatically opens on startup of the program.
For security purposes, I need to check the userID of the person logged in, to allow them access into the program or not. I have put this code in on the "Open" Event. I get the MsgBox for unauthorized users, however, the form still opens (I guess because it set that way in the Startup box.) Any other ideas on how to do this?

Private Sub Form_Open(Cancel As Integer)
On Error GoTo Err_RunReports_Click
If DLookup("OfficeLocation", "tblAuditor", "ChubbID='" & GetUserCredentials(2) & "'") = 1 Then

    Dim stDocName As String
    Dim stLinkCriteria As String

    stDocName = "Splash"
    DoCmd.OpenForm stDocName, , , stLinkCriteria
Else
  MsgBox "You are not authorized to view this form"
  Exit Sub
End If

Exit_RunReports_Click:
    Exit Sub

Err_RunReports_Click:
    MsgBox Err.Description
    Resume Exit_RunReports_Click
End Sub
0
Comment
Question by:4charity
2 Comments
 
LVL 10

Accepted Solution

by:
VTKegan earned 250 total points
ID: 34239576
Try closing the form once the message box displays telling the user they do not have access.

See the code below.
Private Sub Form_Open(Cancel As Integer)
On Error GoTo Err_RunReports_Click
If DLookup("OfficeLocation", "tblAuditor", "ChubbID='" & GetUserCredentials(2) & "'") = 1 Then

    Dim stDocName As String
    Dim stLinkCriteria As String

    stDocName = "Splash"
    DoCmd.OpenForm stDocName, , , stLinkCriteria
Else
  MsgBox "You are not authorized to view this form"
  DoCmd.Close acForm,Me.Name
  Exit Sub
End If

Exit_RunReports_Click:
    Exit Sub

Err_RunReports_Click:
    MsgBox Err.Description
    Resume Exit_RunReports_Click
End Sub

Open in new window

0
 
LVL 57

Assisted Solution

by:Jim Dettman (Microsoft MVP/ EE MVE)
Jim Dettman (Microsoft MVP/ EE MVE) earned 250 total points
ID: 34239583

Else
  MsgBox "You are not authorized to view this form"
  Application.Quit
  Exit Sub
End If

JimD.
0

Featured Post

DevOps Toolchain Recommendations

Read this Gartner Research Note and discover how your IT organization can automate and optimize DevOps processes using a toolchain architecture.

Question has a verified solution.

If you are experiencing a similar issue, please ask a related question

I see at least one EE question a week that pertains to using temporary tables in MS Access.  But surprisingly, I was unable to find a single article devoted solely to this topic. I don’t intend to describe all of the uses of temporary tables in t…
PL/SQL can be a very powerful tool for working directly with database tables. Being able to loop will allow you to perform more complex operations, but can be a little tricky to write correctly. This article will provide examples of basic loops alon…
Familiarize people with the process of utilizing SQL Server views from within Microsoft Access. Microsoft Access is a very powerful client/server development tool. One of the SQL Server objects that you can interact with from within Microsoft Access…
In Microsoft Access, learn how to use Dlookup and other domain aggregate functions and one method of specifying a string value within a string. Specify the first argument, which is the expression to be returned: Specify the second argument, which …

821 members asked questions and received personalized solutions in the past 7 days.

Join the community of 500,000 technology professionals and ask your questions.

Join & Ask a Question