Solved

Auto Open Form on Startup with condition

Posted on 2010-11-30
2
648 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
[X]
Welcome to Experts Exchange

Add your voice to the tech community where 5M+ people just like you are talking about what matters.

  • Help others & share knowledge
  • Earn cash & points
  • Learn & ask questions
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

Why You Need a DevOps Toolchain

IT needs to deliver services with more agility and velocity. IT must roll out application features and innovations faster to keep up with customer demands, which is where a DevOps toolchain steps in. View the infographic to see why you need a DevOps toolchain.

Question has a verified solution.

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

Suggested Solutions

Title # Comments Views Activity
Excel graph in access report 1 34
T-SQL: need to reset a declared variable 4 33
Outlook mail to Access 8 31
SQL multiple joins 2 17
Describes a method of obtaining an object variable to an already running instance of Microsoft Access so that it can be controlled via automation.
As tax season makes its return, so does the increase in cyber crime and tax refund phishing that comes with it
What’s inside an Access Desktop Database. Will look at the basic interface, Navigation Pane (Database Container), Tables, Queries, Forms, Report, Macro’s, and VBA code.
With Secure Portal Encryption, the recipient is sent a link to their email address directing them to the email laundry delivery page. From there, the recipient will be required to enter a user name and password to enter the page. Once the recipient …

752 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