Solved

Auto Open Form on Startup with condition

Posted on 2010-11-30
2
614 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
Comment Utility
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
Comment Utility

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

JimD.
0

Featured Post

Free Gift Card with Acronis Backup Purchase!

Backup any data in any location: local and remote systems, physical and virtual servers, private and public clouds, Macs and PCs, tablets and mobile devices, & more! For limited time only, buy any Acronis backup products and get a FREE Amazon/Best Buy gift card worth up to $200!

Join & Write a Comment

Suggested Solutions

Title # Comments Views Activity
mySql Syntax 7 26
putting an icon in a form 13 20
How to calcualate lateness in Access 2010 11 22
Error in SQL Query 36 33
Introduction The Visual Basic for Applications (VBA) language is at the heart of every application that you write. It is your key to taking Access beyond the world of wizards into a world where anything is possible. This article introduces you to…
If you have heard of RFC822 date formats, they can be quite a challenge in SQL Server. RFC822 is an Internet standard format for email message headers, including all dates within those headers. The RFC822 protocols are available in detail at:   ht…
Familiarize people with the process of utilizing SQL Server functions 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 Ac…
Familiarize people with the process of retrieving data from SQL Server using an Access pass-thru query. Microsoft Access is a very powerful client/server development tool. One of the ways that you can retrieve data from a SQL Server is by using a pa…

744 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

Need Help in Real-Time?

Connect with top rated Experts

14 Experts available now in Live!

Get 1:1 Help Now