Solved

Auto Open Form on Startup with condition

Posted on 2010-11-30
2
652 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 58

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

Technology Partners: We Want Your Opinion!

We value your feedback.

Take our survey and automatically be enter to win anyone of the following:
Yeti Cooler, Amazon eGift Card, and Movie eGift Card!

Question has a verified solution.

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

You need to know the location of the Office templates folder, so that when you create new templates, they are saved to that location, and thus are available for selection when creating new documents.  The steps to find the Templates folder path are …
If you need a simple but flexible process for maintaining an audit trail of who created, edited, or deleted data from a table, or multiple tables, and you can do all of your work from within a form, this simple Audit Log will work for you.
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 …
Visualize your data even better in Access queries. Given a date and a value, this lesson shows how to compare that value with the previous value, calculate the difference, and display a circle if the value is the same, an up triangle if it increased…

623 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