Link to home
Start Free TrialLog in
Avatar of 4charity
4charity

asked on

Auto Open Form on Startup with condition

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
ASKER CERTIFIED SOLUTION
Avatar of VTKegan
VTKegan
Flag of United States of America image

Link to home
membership
This solution is only available to members.
To access this solution, you must be a member of Experts Exchange.
Start Free Trial
SOLUTION
Link to home
membership
This solution is only available to members.
To access this solution, you must be a member of Experts Exchange.
Start Free Trial